What is Base64?
Base64 is a binary-to-text encoding defined in RFC 4648. It takes arbitrary bytes and represents them with 64 printable ASCII characters: the uppercase letters A-Z, the lowercase letters a-z, the digits 0-9, and two extra symbols, + and /. A 65th character, =, is used as padding at the end.
The point is not to hide data but to make it transportable. Many systems were built to carry text and break on raw binary: email servers that strip the 8th bit, JSON and XML parsers that reject control characters, HTTP headers that cannot contain newlines. Base64 turns any file or byte sequence into a string those systems pass through untouched. On the other side, decoding returns the exact original bytes.
How Base64 Encoding Works
Base64 works on groups of 3 bytes (24 bits) at a time and splits each group into four 6-bit numbers. Each 6-bit number (0-63) is an index into the alphabet A-Z a-z 0-9 + /.
Take the word Man:
| M | a | n | |
|---|---|---|---|
| ASCII | 77 | 97 | 110 |
| Bits | 01001101 | 01100001 | 01101110 |
Regrouped into 6-bit chunks: 010011 010110 000101 101110 → 19, 22, 5, 46 → TWFu.
When the input length is not a multiple of 3, the last group is short. The encoder pads it with zero bits and adds = characters to show how many bytes were missing:
Hi(2 bytes) →SGk=(one=)H(1 byte) →SA==(two=)
That is why a Base64 string ends with at most two = signs, and why its padded length is always a multiple of 4. It is also where the 33% size overhead comes from: 3 bytes in, 4 characters out.
How to Use This Tool
- Paste text or a Base64 string into the input box.
- Click Encode to turn text into Base64, or Decode to turn Base64 back into text.
Ctrl+Enterruns whichever button is highlighted. - Copy the result with the Copy button or
Ctrl+Shift+C.Ctrl+Lclears the input.
As you type, the tool looks at the input. If it is clearly Base64 (only Base64 characters, a valid length, longer than 10 characters, or a data:...;base64, prefix), Decode becomes the highlighted action. If it contains spaces or punctuation that Base64 never uses, Encode is highlighted. You can always click either button yourself.
Encoding converts your text to UTF-8 first, so accented letters, Cyrillic, CJK and emoji all round-trip correctly. Tick URL-safe to get Base64url output (- and _, no padding) for URLs, cookies, filenames and JWT segments.
Decoding is deliberately forgiving about the formats people actually paste:
- standard Base64 and URL-safe Base64url, even mixed;
- missing
=padding; - line breaks every 64 or 76 characters, as in PEM files and email;
- full data URIs such as
data:image/png;base64,iVBORw0..., where the prefix is stripped automatically.
If the decoded bytes are valid UTF-8, you see the text. If they are not, for example because the Base64 contained an image or a gzip stream, you get the byte count, a file-type hint (PNG, JPEG, GIF, PDF, ZIP, gzip) and a hex dump instead of a screen of replacement characters. To turn a Base64 image back into a picture, use the Base64 Image Encoder.
Base64 vs Base64url
Standard Base64’s + and / have special meanings in URLs (+ can be read as a space, / is a path separator), and = separates query parameters. RFC 4648 therefore defines a URL- and filename-safe variant:
| Standard Base64 | Base64url | |
|---|---|---|
| Characters 62 and 63 | + and / | - and _ |
| Padding | = required | usually omitted |
| Used by | MIME email, PEM keys, data URIs, HTTP Basic auth | JWT, WebAuthn, OAuth PKCE, URL parameters |
If a decoder rejects a string containing - or _, it is Base64url. Swap the two characters back (or use a decoder that accepts both, like this one) and add padding until the length is a multiple of 4.
Where You’ll Meet Base64
- Data URIs: small images and fonts inlined in HTML or CSS,
data:image/svg+xml;base64,.... - HTTP Basic authentication: the header
Authorization: Basic dXNlcjpwYXNzis justuser:passin Base64. Anyone who sees the header can read the password, which is why Basic auth is only acceptable over HTTPS. - JSON Web Tokens: the header and payload of a JWT are Base64url-encoded JSON. Decoding a single segment shows the claims; the JWT Decoder splits and formats all three parts at once.
- Email attachments: MIME encodes attachments in Base64, wrapped at 76 characters per line.
- Kubernetes Secrets: values under
data:in a Secret manifest are Base64-encoded, not encrypted. - PEM certificates and keys: everything between
-----BEGIN CERTIFICATE-----and-----END CERTIFICATE-----is Base64-encoded DER. - APIs: file uploads, image generation results and binary blobs are often returned as Base64 strings inside JSON.
Common Base64 Decode Errors
“Invalid character”: the string contains something outside the Base64 alphabet. Common culprits are a stray quote or comma copied from JSON, a %3D that is really a URL-encoded = (run it through the URL decoder first), or a . because the input is actually a JWT.
“Invalid length”: after removing padding, a valid Base64 string can never have a length of 4n+1 characters. This almost always means the value was truncated when it was copied, for example cut off by a log line limit or a terminal width.
Padding in the middle: an = followed by more characters usually means two Base64 strings were concatenated. Decode them separately.
Garbled text (mojibake): if the output looks like é where you expected é, the original text was encoded with a different character set, such as Windows-1252 or UTF-16, before it was Base64-encoded. If the output shows a hex dump, the data was never text in the first place.
btoa() “characters outside of the Latin1 range”: a JavaScript-specific error. btoa() only accepts one-byte characters. Encode the string to UTF-8 bytes first (see below).
Encoding and Decoding Base64 in Code
JavaScript (browser), with UTF-8 handled correctly:
const bytes = new TextEncoder().encode('héllo ✓');
const b64 = btoa(String.fromCharCode(...bytes)); // "aMOpbGxvIOKckw=="
const text = new TextDecoder().decode(
Uint8Array.from(atob(b64), c => c.charCodeAt(0))
);
Newer browsers also ship Uint8Array.fromBase64() and bytes.toBase64(), which accept an { alphabet: "base64url" } option.
Node.js: Buffer.from('hello').toString('base64') and Buffer.from(b64, 'base64').toString('utf8'). Use 'base64url' for the URL-safe variant.
Python: base64.b64encode(b'hello'), base64.b64decode(s), and base64.urlsafe_b64encode() / urlsafe_b64decode() for Base64url.
Command line: echo -n 'hello' | base64 encodes and echo 'aGVsbG8=' | base64 -d decodes (older macOS versions use -D). Leave out -n and the trailing newline is encoded too: aGVsbG8K instead of aGVsbG8=, one of the most common “why doesn’t my Base64 match” surprises.
Base64 Is Not Encryption
Base64 has no key and no secret. It is as easy to reverse as it is to apply, and tools like this one do it instantly. Treat a Base64-encoded password, API token or Kubernetes Secret as plain text. If data needs to stay confidential, encrypt it. If you need a fingerprint to check integrity, use a hash function. Base64 only solves one problem: getting bytes through a text-only channel intact.