The Problem Base64 Solves
Many systems — email, JSON, URLs, older text-based protocols — were designed to reliably carry plain text, not arbitrary binary data. Binary data (like an image file) can contain byte sequences that these text-based systems misinterpret, corrupt, or reject outright. Base64 solves this by representing any binary data using only a safe set of 64 printable characters (letters, digits, and a couple of symbols) that virtually every text-based system can handle without issue.
How It Works, Conceptually
Base64 takes the raw bytes of your data and re-represents them using groups of 6 bits mapped to one of 64 possible characters (hence "base 64"), rather than the usual 8-bits-per-byte representation. This is why encoded output is always somewhat longer than the original — roughly 33% larger — since it takes more characters to represent the same information using this smaller, text-safe character set.
Common Places You'll Encounter It
- Data URIs: embedding an image directly inside HTML or CSS as a Base64 string, avoiding a separate file request.
- Email attachments: traditional email protocols encode binary attachments in Base64 to travel safely through text-based mail systems.
- API authentication: HTTP Basic Authentication headers encode credentials in Base64 before sending them.
- JSON Web Tokens (JWTs): the header and payload sections of a JWT are Base64-encoded (specifically, a URL-safe variant).
The One Thing Worth Remembering
Base64 is a way of representing data safely for text-based systems — it is not compression (the output is larger, not smaller) and it is not encryption (anyone can decode it instantly, with no key or password required). Understanding that distinction clears up most of the common confusion around what Base64 actually does.
Ready to see Base64 encoding in action?
Try It Yourself