You've probably seen a long string of letters, numbers, and a few +, /, and
= characters somewhere in an API response, an email attachment, or a data: URL in a
stylesheet. That's almost certainly Base64 — one of the quietest, most widely used pieces of internet
infrastructure, and one that's frequently misunderstood as a form of security.
The problem Base64 solves
Lots of systems were designed to handle text, not arbitrary binary data. Email, in particular, was built
around 7-bit ASCII text decades ago, and plenty of modern systems (JSON strings, URLs, XML) still expect
plain, printable characters. But images, PDFs, and other binary files are just raw bytes, including many byte
values that don't correspond to printable characters at all, and some of which would be actively
misinterpreted by text-oriented systems (like a byte that happens to look like a line-ending or control
character). Base64 solves this by re-encoding any binary data into a string made up entirely of 64
safe, printable characters — letters, digits, +, and / — that can pass
through text-only systems without corruption.
How it works, conceptually
Base64 takes your data 3 bytes (24 bits) at a time, and repackages those 24 bits into 4 characters of 6 bits
each, since 6 bits is exactly enough to represent 64 distinct values (26 = 64) — hence the
name. Each 6-bit chunk maps to one character from a fixed alphabet: A–Z, a–z, 0–9, plus two
more symbols (typically + and /) to reach 64 total. If the input isn't a clean
multiple of 3 bytes, one or two = padding characters get added at the end to keep the output
length consistent.
The practical result: Base64-encoded data is always about 33% larger than the original binary. That's the trade-off for making it safely text-representable.
A concrete example
The text "Hi!" encodes to:
SGkh
Three characters of input became four characters of output — consistent with the 3-bytes-in, 4-characters-out pattern. Decoding reverses the process exactly, recovering the original three bytes.
Where you actually run into Base64
- Email attachments (MIME). Email was built for text; Base64 is how a PDF or image gets safely embedded in a message that's fundamentally a stream of text.
- Data URLs in CSS/HTML.
background-image: url(data:image/png;base64,iVBORw0KG...)embeds a small image's actual bytes directly inline, avoiding a separate HTTP request for a tiny icon. - HTTP Basic Authentication. The
Authorization: Basic <credentials>header contains a Base64-encodedusername:passwordpair — readable, not secret, which is exactly why Basic Auth requires HTTPS to actually protect those credentials in transit. - Encoding binary in JSON. JSON strings can only hold text, so a binary file (like a small image or a cryptographic key) being sent inside a JSON payload usually gets Base64-encoded first.
- JWTs. Each of the three dot-separated parts of a JSON Web Token is Base64URL-encoded (a URL-safe variant that swaps a couple of characters).
The one thing everyone eventually gets wrong: Base64 is not encryption
This deserves to be said plainly: Base64 provides zero confidentiality. It's a reversible encoding scheme with a completely public, standardized algorithm — there's no secret key involved anywhere in the process. Anyone can decode a Base64 string back to its original form in one line of code, in any language, instantly. If you see Base64-encoded data and think "that's obfuscated, so it's probably safe to expose," that assumption is wrong. Treat Base64-encoded sensitive data exactly as if it were sent in plain text, because functionally, it is.
Base64 vs. Base64URL
Standard Base64 uses + and / as two of its 64 characters. Both of those have
special meaning inside a URL (+ can mean a space, / separates path segments), so
using standard Base64 directly inside a URL can break things. Base64URL is a small variant that swaps
+ for - and / for _, and typically drops the trailing
= padding, making the result safe to use directly inside a URL or filename without further
escaping. This is the variant JWTs use.
A quick way to sanity-check what you're looking at
If a string is made up only of letters, digits, and possibly +, /, or
= at the end (or -, _ for the URL-safe variant), and its length is a
multiple of 4, there's a good chance it's Base64. Decoding it takes a fraction of a second and often
immediately clarifies what you're actually looking at — readable text, a small image, or structured
binary data.
Frequently Asked Questions
= signs may appear depending on how much padding was needed.+ and /) with URL-safe alternatives (- and _), and usually omits padding — making it safe to use directly inside a URL or filename.