What is Base64 encoding in simple terms?
Base64 rewrites binary data as plain text. It reads three bytes at a time and turns each group into four characters from a fixed 64-character alphabet, so the output runs about a third larger than the input. Encoding is not encryption. Anyone can decode a Base64 string without a key.
You have seen it even if you did not know its name. A long, dense run of letters, digits, plus signs and slashes, often ending in one or two equals signs, sitting inside an email header, a config file, or the middle of a web page’s source. That is Base64. It is a way of rewriting any data, including raw binary, as a string of plain text characters that almost any system will accept without choking.
The reason it exists is older than it looks. Plenty of the channels we move data through were built to carry text and only text. Email is the classic example. Send a raw image or a zip file straight down a protocol designed for ASCII and some byte will eventually be misread, mangled, or stripped out. Base64 sidesteps that by restricting itself to a small, safe set of characters that survive the trip intact.
How does Base64 work?
Computers store everything as bytes, and a byte can hold any of 256 values. The problem is that a lot of those values are not printable characters. Some are control codes, some get interpreted as line breaks or end-of-data markers, and some get quietly altered by the systems they pass through. Base64 solves this by mapping arbitrary bytes onto a fixed alphabet of 64 characters that are known to be safe: the 26 uppercase letters, the 26 lowercase letters, the 10 digits, and two extras, usually + and /.
The mechanism is tidy. Base64 reads your data in groups of 3 bytes. Three bytes is 24 bits, and 24 divides neatly into four 6-bit chunks. Each 6-bit chunk can represent a number from 0 to 63, which is exactly one character from the 64-character alphabet. So every 3 bytes of input become 4 characters of output. That four-for-three ratio is why a Base64 string is always about a third larger than the data it represents.
The padding, explained
Your data is rarely a perfect multiple of 3 bytes. When the final group comes up short, Base64 still emits a full block of 4 characters and signals the shortfall with the = sign. One equals means the last group had two bytes, two equals means it had one. The padding is just bookkeeping so a decoder knows exactly how many real bytes to reconstruct. It is structure, not content, which is why those trailing equals signs are such a giveaway that you are looking at Base64.
Is Base64 a form of encryption?
This is the single biggest misconception, and it matters. Base64 looks scrambled, so people assume it hides something. It does not. There is no key, no password, and no secret involved. The transformation is completely reversible by anyone, and decoding takes no special permission. If you Base64-encode a password and paste it into a file, you have not protected it at all. You have just made it slightly less obvious to a human skimming the file, while leaving it trivially readable to any machine, and most people.
Encoding and encryption answer different questions. Encoding asks “how do I represent this data in a form this system accepts?” Encryption asks “how do I make this data unreadable to everyone except the holder of the key?” Base64 is firmly in the first camp. It is closer in spirit to a hash function only in that both transform data, but even that comparison breaks down fast: a hash is one-way and Base64 is two-way by design. If the difference between scrambling for transport and scrambling for secrecy is fuzzy, our piece on hashing versus encryption draws the lines clearly.
Where will you see Base64?
Once you know the shape of a Base64 string, you start seeing it everywhere. A few of the common places:
- Email attachments. Every image, PDF and document you attach to an email is Base64-encoded behind the scenes so it can ride through a text-based mail protocol. This is the original use case, and it is still the biggest one by volume.
- Data URLs. A small image embedded directly in HTML or CSS with data:image/png;base64, followed by a wall of characters is a Base64-encoded file, inlined so the browser does not need a separate request.
- JWTs. The header and payload of a JSON Web Token are Base64-encoded JSON. That is why you can decode a JWT and read its contents without any key, and why you should never put secrets in one.
- Basic Authentication. HTTP Basic Auth sends your username and password joined by a colon and Base64-encoded in a header. Encoded, not encrypted, which is exactly why Basic Auth must only ever run over HTTPS.
- Keys and certificates. The PEM format you see in .pem and .crtfiles, with its BEGIN and END markers, wraps Base64-encoded binary key material so it can sit safely in a text file.
URL-safe Base64 and other variants
The two extra characters in the standard alphabet, + and /, cause trouble in some places. A forward slash means something specific in a URL, and a plus sign can be read as an encoded space. So there is a URL-safe variant that swaps those two for - and _, and often drops the padding entirely. JWTs use this URL-safe form. It is the same idea with two characters changed, so a slightly different-looking string should not throw you.
You will also see Base64 strings broken into fixed-width lines, particularly in email and PEM files. That line wrapping is cosmetic, a holdover from old format limits, and a decoder ignores it.
When should you use Base64?
Use Base64 when you genuinely need to carry binary data through a text-only channel: embedding a tiny image in a stylesheet, stuffing a small blob into a JSON field, or moving a key around as text. It is the right tool for those jobs and it is everywhere for good reason.
Avoid it for two things. First, never treat it as security. If the data needs to stay private, encrypt it. Second, be wary of Base64-ing large files when you have an alternative, because that 33 percent size penalty adds up and there is usually a more efficient path. Beyond that, it is a quiet, reliable workhorse. If you spend time in a terminal, it sits right alongside the other formats worth understanding, like the UUID, and it is one more thing that makes copying and pasting in the terminal feel less like guesswork.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings, RFC Editor (2006)
- Base64, MDN Web Docs
- RFC 2045: MIME Part One, Format of Internet Message Bodies, RFC Editor (1996)
- data: URLs, MDN Web Docs