">
A complete guide to Base64 encoding and decoding: what it is, how it works, when to use it, and a free tool to do it instantly in your browser.
Base64 is a binary-to-text encoding scheme that converts binary data into a string of ASCII characters. It uses a set of 64 characters (A-Z, a-z, 0-9, +, /) plus = for padding to represent binary data in a text-safe format.
The name "Base64" comes from the 64-character alphabet used. Every 3 bytes of binary data become 4 Base64 characters. This means Base64-encoded data is about 33% larger than the original, but it is guaranteed to be safe for text-based protocols.
Let's walk through encoding the string "Hi" in Base64:
H = 72 = 01001000 i = 105 = 01101001
01001000 01101001
010010 000110 1001(00) ← padded with zeros to complete the group
010010 = 18 = S 000110 = 6 = G 100100 = 36 = k
Since the input was 2 bytes (not divisible by 3), one = padding character is added:
"Hi" → "SGk="
Data URIs let you embed small images directly in your code, eliminating an HTTP request:
<img src="data:image/png;base64,iVBORw0KGgo..." />
This is useful for small icons (under 5KB). For larger images, a separate file is more efficient because browsers can cache it independently.
Email protocols (SMTP) were designed for text. Binary attachments — images, PDFs, archives — are Base64-encoded before being embedded in the email body. Your email client handles this automatically, but understanding it helps when debugging email delivery issues.
HTTP Basic Authentication sends credentials as a Base64-encoded string in the Authorization header:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Decoding dXNlcm5hbWU6cGFzc3dvcmQ= gives username:password. This is why HTTPS is mandatory when using Basic Auth — Base64 provides no security.
JSON does not support binary data natively. If you need to include a file, image, or binary blob in a JSON payload, Base64 encoding is the standard approach:
{
"filename": "document.pdf",
"content": "JVBERi0xLjQKMSAwIG9iago8P..."
}
JSON Web Tokens use Base64URL encoding (a URL-safe variant) for the header and payload sections. If you have ever inspected a JWT, the three dot-separated sections are each Base64URL-encoded JSON.
Beyond images, data URLs can embed fonts, SVGs, audio, and other resources directly in CSS or HTML. This reduces HTTP requests at the cost of larger file sizes and no caching.
// Encode
const encoded = btoa("Hello, World!");
// "SGVsbG8sIFdvcmxkIQ=="
// Decode
const decoded = atob("SGVsbG8sIFdvcmxkIQ==");
// "Hello, World!"
import base64
# Encode
encoded = base64.b64encode(b"Hello, World!").decode()
# "SGVsbG8sIFdvcmxkIQ=="
# Decode
decoded = base64.b64decode("SGVsbG8sIFdvcmxkIQ==").decode()
# "Hello, World!"
// Encode
const encoded = Buffer.from("Hello, World!").toString("base64");
// Decode
const decoded = Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64").toString();
# Encode (macOS/Linux) echo -n "Hello, World!" | base64 # Decode echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
Standard Base64 uses + and / characters, which have special meaning in URLs. Base64URL replaces these with - and _, making the output safe for use in URLs, filenames, and query parameters without additional encoding.
JWT tokens use Base64URL. URL parameters use Base64URL. Standard Base64 is fine for everything else.
Base64 is not encryption. It is trivially reversible. Never Base64-encode passwords, API keys, or secrets and assume they are protected. Use proper encryption (AES-256, for example) if you need to protect data.
Base64 increases data size by approximately 33%. A 1MB image becomes 1.33MB when Base64-encoded. For large files, this overhead is significant. Use Base64 for small assets only; serve large files as regular binary downloads.
Encoding something that is already Base64-encoded does not provide any benefit. It just wastes space. If your Base64 string looks wrong (too long, unusual characters), check if it was accidentally encoded twice.
Our Base64 Encoder/Decoder handles both encoding and decoding in your browser. Paste text or Base64, click the button, get your result. No server involved, no tracking, no signup.
You can also use the advanced Base64 tool for file encoding, URL-safe mode, and batch operations.
Encode or Decode Base64 Instantly
Free. No signup. No tracking. Runs in your browser.
Open Base64 ToolExplore all 300+ free developer tools on spunk.codes.