Convert text to and from Base64 encoding
Base64 Converter
Convert text to and from Base64 encoding
Input (Text/File)
Output (Base64)
Base64 makes your data bigger on purpose — and that's literally the point
I know that sounds backwards. You'd think encoding means compression. It doesn't. Base64 takes every 3 bytes of binary data and turns them into 4 printable ASCII characters. Three bytes in, four characters out — that's a guaranteed 33% size increase every single time. The reason exists because a huge chunk of infrastructure was built for text: email servers, HTTP headers, JSON values. Shove raw binary bytes through them and they break in different ways on different systems. Base64 sidesteps that entirely by converting everything to a 64-character alphabet that every text-safe transport can handle without choking.
| Variant | Chars 62–63 | Padding | Where you'll actually see it |
|---|---|---|---|
| Standard — RFC 4648 | + / | = required | PEM certificates, email attachments |
| URL-safe — RFC 4648 §5 | - _ | = optional | JWT tokens, URL query params |
| MIME — RFC 2045 | + / | = required | Email body, hard-wrapped at 76 chars |
That = padding sign has caused more "invalid length" errors than I care to count
It's not decoration. When your input byte count isn't divisible by 3, the encoder pads the last group with one or two = signs to make the output length divisible by 4. Standard decoders expect it. URL-safe decoders often don't care. Here's the trap that gets people: you pull a JWT out of a cookie, try to decode the payload server-side, get an "invalid Base64 length" error, and spend 45 minutes convinced the JWT is malformed. The actual fix takes ten seconds — append = signs until string.length % 4 === 0. It's just padding. That's all it ever was.
Embedding images as data URIs: looks like an optimization, usually isn't
Yes, you save one HTTP request. But a 500 KB PNG encodes to roughly 682 KB of Base64 text. Chrome's V8 stores JavaScript strings at 2 bytes per character. That's 1.36 MB of heap just to hold the string, before the browser even starts decoding it back to pixels. The image you were "optimizing" now burns more memory than a plain URL would have. Data URIs are fine for tiny inline icons, maybe 2–3 KB tops. Anything bigger: use a URL. The browser caches it. Everyone is happier.
Terminal commands to save somewhere you'll actually find them
Linux: echo -n "hello" | base64 outputs aGVsbG8=. Decode: echo "aGVsbG8=" | base64 --decode. On macOS the flag is -D not --decode — that inconsistency has annoyed people for decades and Apple has never fixed it. PowerShell: [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("hello")) to encode; [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("aGVsbG8=")) to decode. Bookmark these. You'll need them every few months and you'll never remember the exact syntax.
