Base64 Encoding Explained: What It Is and When (Not) to Use It
July 15, 2026 · 6 min read
You've met Base64 whether you noticed or not. It's hiding in JWT tokens, inlined CSS images, every email attachment you've ever sent. It's also one of the most misunderstood things in web dev — I've reviewed code where someone Base64'd a password and called it encryption. (It's not. Nothing even close.) So let's settle what Base64 actually is and when it's the right tool.
The problem it solves
Text-based systems are fussy eaters. Put raw binary into an email body, an XML attribute or a JSON string and something along the way will mangle it — control characters stripped, line endings rewritten, encodings 'helpfully' fixed. Base64 sidesteps all of that by translating bytes into an alphabet of just 64 boring characters: A–Z, a–z, 0–9, plus + and /. Every text system on the planet passes those through untouched.
The mechanism is simpler than people expect: take every 3 bytes (24 bits), split into four 6-bit chunks, map each chunk to one of the 64 characters. Decoding runs it backwards. That's genuinely all of it — paste any string into our Base64 Encoder and watch.
The 33% tax nobody budgets for
The size increase isn't a flaw, it's arithmetic. Three bytes in, four characters out — always. That's a fixed 33.3% overhead. Your 100 KB image becomes about 133 KB of text. A 1 MB file becomes 1.33 MB that someone transfers, parses and holds in memory. Base64 buys text-safety at a fixed rate, and the rate is not small.
When embedding is actually smart
Data URLs (src="data:image/png;base64,iVBOR…") put a file inline in a document. Done right, that's useful. Tiny icons in CSS under ~2 KB, where skipping an HTTP request beats the size tax. Single-file HTML reports that must work offline. Email HTML, where remote images get blocked anyway. In all three, one self-contained file is worth more than perfect efficiency.
When it isn't
- Big images in web pages — a 500 KB photo becomes 665 KB of text that can't be cached or deferred properly
- Anything bundled into JavaScript — it bloats parse time and bypasses caching
- Secrets, tokens, passwords — anyone can decode it instantly; obfuscation is not protection
- High-traffic assets — embedded content re-downloads on every single page view
Email's quiet dependency
Fun fact: every attachment you've ever emailed traveled as Base64. SMTP dates from the era of 7-bit ASCII text, so MIME wraps attachments in Base64 to survive the trip. This explains a famous confusion: a provider's "25 MB limit" counts the encoded size. Keep your actual files under about 18 MB or the encoding overhead pushes you over the limit.
Stuff that bites developers in practice
Three recurring traps. First, btoa()/atob() in browsers break on Unicode — encode to UTF-8 bytes first or you'll corrupt any non-ASCII text. Second, URL-safe Base64 swaps + and / for - and _ so strings can live in URLs unescaped; that's the flavor inside JWT payloads. Third, debugging: if an API hands you Base64 file content, our Base64 Encoder/Decoder handles both directions, does UTF-8 properly, accepts dropped files, and runs locally — handy when the payload is something sensitive.
Base64 has earned its permanent spot in the toolbox. Sixty-four safe characters, a 33% tax, binary data that survives anywhere. Use it for transport and tiny embeds, keep it away from big assets and anything secret, and it'll never surprise you again.