TToolsPilots
Все статьи

Base64 Encoding Explained: What It Is and When (Not) to Use It

July 15, 2026 · 6 мин чтения

You've seen Base64 even if you didn't notice it: the long strings ending in "==" inside JWT tokens, inlined images in CSS, email attachments, API payloads. It's everywhere in computing — and it's widely misunderstood. Base64 is not encryption, not compression, and not free. Here's what it actually is, and when you should (and shouldn't) use it.

The problem Base64 solves

Computers store everything as bytes, and many bytes don't survive a trip through text-based systems. Binary data in an email body, an XML attribute or a JSON string can get mangled: control characters are stripped, line endings are rewritten and encodings are 'helpfully' converted. Base64 solves this by translating any binary data into a safe alphabet of just 64 characters — A–Z, a–z, 0–9, + and / — that passes through every text system untouched.

The mechanics: every 3 bytes (24 bits) are split into four 6-bit groups, and each 6-bit group maps to one character from the 64-character alphabet. That's the whole trick. Decoding just reverses it. Try it right now with our Base64 Encoder — paste any text and watch it transform.

Why Base64 makes data ~33% bigger

The math follows directly from the encoding: 3 bytes become 4 characters. Four characters where three bytes used to be means 4/3 as much data — a 33.3% size increase, always. A 100 KB image becomes about 133 KB of Base64 text. A 1 MB file becomes 1.33 MB that someone has to transfer, parse and hold in memory. There's no compression involved; Base64 pays a fixed tax for text-safety.

When embedding makes sense: data URLs

A data URL embeds a resource directly in a document: src="data:image/png;base64,iVBORw0KG...". Legitimate uses include tiny icons and logos in CSS (under ~2 KB, where saving an HTTP request outweighs the size tax), single-file HTML reports that must work offline and email HTML where remote images get blocked by default. In these cases, one self-contained file is more valuable than perfect efficiency.

When NOT to embed

  • Large images on web pages — a 500 KB photo becomes 665 KB of uncacheable text that blocks rendering; use a normal file or CDN instead
  • Anything in a JavaScript bundle — it inflates parse time and can't be cached separately
  • Genuine secrets — Base64 is reversible by anyone, instantly; decoding is not 'hacking'
  • High-traffic assets — every page load re-downloads the embedded data; external files can be cached for a year

Email: the invisible workhorse

Every attachment in every email you've ever sent traveled as Base64. SMTP, the email protocol, was designed for 7-bit ASCII text, so MIME encoding wraps attachments in Base64 to survive the journey. This is also why email attachment limits feel smaller than advertised: a provider's '25 MB limit' means 25 MB of encoded data, so your actual files should total under roughly 18 MB before encoding overhead pushes you over.

Practical tips for developers

A few things that come up constantly: browsers offer btoa()/atob() but they break on Unicode text — encode to UTF-8 bytes first. URL-safe Base64 replaces + and / with - and _ so encoded strings can live in URLs without escaping (it's what the payload of a JWT uses). And if you're debugging an API that returns Base64 file content, our Base64 Encoder/Decoder decodes both directions, handles UTF-8 correctly and accepts file drops to encode any file — all locally in your browser, so even sensitive payloads stay private.

Base64 is one of those simple ideas that earns its place in the toolbox forever: 64 safe characters, a 33% tax, and binary data that survives anywhere. Use it for transport and small embeds, avoid it for big assets and secrets, and you'll never be surprised by it again.

Попробуйте инструменты