Base64 is a way of writing any data — an image, a file, text in any language — using only 64 safe characters: A to Z, a to z, 0 to 9, plus + and /. It exists because some systems can only carry plain text, and raw binary data does not survive the trip. Base64 re-writes the data as ordinary text characters, so it passes through email, URLs, and JSON without being mangled. It is defined by RFC 4648, the internet standard for it.
If you have ever seen a long string of letters, numbers, and = signs at the end — in an email attachment, a data URI, or a login token — you have seen Base64. This guide explains how it works, why the = appears, where you meet it every day, and the one thing it is not: encryption.

Why Base64 Exists: Binary Data Can’t Travel as Text
Computers store everything as bytes — numbers from 0 to 255. Text systems, historically, only handled a small subset of those safely. Early email could carry the 95 printable ASCII characters and not much else. A byte with value 0, or 200, or a byte that happened to look like a control character, could be dropped, altered, or misread somewhere along the way.
That was a real problem the first time someone wanted to email a photo. The image file is binary: its bytes include every value from 0 to 255, including ones that email servers of the early 1990s would corrupt. The fix, standardised for email as MIME and later codified as Base64 in RFC 4648 (2006), was to re-encode the binary data using only characters that every system handles identically.
Base64’s answer is a restricted alphabet of exactly 64 characters, all of them plain printable ASCII. Any byte sequence, no matter what it contains, can be re-written using only those characters. The result is slightly larger than the original — about a third larger, as we will see — but it survives every text-based channel: email bodies, JSON fields, URLs, HTML attributes, config files, and copy-paste.
The same problem still shows up today. JSON has no binary type, so an API that needs to send a small image inside a JSON response encodes it as Base64. A web page that wants an image embedded directly in the HTML, with no separate file, uses a Base64 data URI. A login token that must fit in an HTTP header uses the URL-safe Base64 variant. Different decades, same trick.
How Base64 Works: 3 Bytes Become 4 Characters
The core idea fits in one sentence: Base64 re-slices a byte stream from 8-bit groups into 6-bit groups, then maps each 6-bit value (0–63) to a printable character.
Why 6 bits? Because 26 = 64, and 64 distinct characters fit comfortably in printable ASCII. Each output character carries exactly 6 bits of the original data.
Three bytes is the natural input unit: 3 bytes = 24 bits, and 24 is the least common multiple of 8 and 6. Three 8-bit bytes divide evenly into four 6-bit groups with nothing left over. The encoder processes input in 3-byte chunks, emitting 4 characters per chunk.
Take the classic example from RFC 4648 itself, the 3-byte string Man:
M = 01001101
a = 01100001
n = 01101110
Joined: 010011 010110 000101 101110
Values: 19 22 5 46
Chars: T W F u
Man -> TWFu
Each 6-bit group becomes one character by looking it up in the alphabet: 19 is T, 22 is W, 5 is F, 46 is u. Decoding is the mirror image: characters back to 6-bit values, regrouped into 8-bit bytes. The process is exactly reversible — decoding TWFu gives back Man, byte for byte, with no loss.
The price is size. Because 3 input bytes always become 4 output characters, Base64 output is 4/3 the size of the input — a fixed 33% overhead. A 300 KB image becomes about 400 KB when encoded. That is a hard mathematical floor, not an implementation detail, and it is the main reason you would not Base64-encode a large video.
The 64-Character Alphabet and the = Padding
The standard Base64 alphabet from RFC 4648 §4 is:
| Values | Characters |
|---|---|
| 0–25 | A–Z |
| 26–51 | a–z |
| 52–61 | 0–9 |
| 62 | + |
| 63 | / |
The = sign is not part of the alphabet. It is padding, and it appears only at the end. It exists because input does not always come in neat 3-byte chunks. When the final chunk has 1 or 2 bytes instead of 3, the encoder pads the last group with zero bits and marks the filler with =:
| Input | Bytes | Base64 | Padding |
|---|---|---|---|
M |
1 | TQ== |
Two = signs: the last group held one byte |
Ma |
2 | TWE= |
One =: the last group held two bytes |
Man |
3 | TWFu |
None: a full chunk |
Hello |
5 | SGVsbG8= |
One =: 3 + 2 bytes |
Padding does two jobs. It tells the decoder exactly how many real bytes the final group contains — without it, the decoder could not distinguish trailing zero bits from real data. And it keeps every Base64 output a multiple of 4 characters long, which is a quick validity check: if a supposedly Base64 string’s length is not divisible by 4, something is wrong with it.
One common variant breaks that rule deliberately. Base64url, defined in RFC 4648 §5, replaces + with - and / with _, and usually drops the padding entirely, because +, /, and = all have special meanings in URLs. Decoders for that variant infer the padding from the string length instead. If a decoder rejects a string full of - and _, it is probably base64url: swap them back to + and /, add = until the length is a multiple of 4, and it will decode.

Where You Meet Base64 Every Day (Data URIs, JWTs, Email)
Email attachments. This is the original use case. MIME email encodes attachments as Base64 so they survive mail servers that only handle text. Open the raw source of an email with an attachment and you will see pages of Base64 between the headers.
Data URIs in web pages. A small image can be embedded directly in HTML or CSS instead of loaded as a separate file:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...">
The browser decodes the Base64 and renders the image. This is handy for tiny icons and single-file HTML pages, but the 33% size cost means it is a bad idea for large images — and the image cannot be cached separately from the page.
JWTs and API tokens. JSON Web Tokens use base64url for all three of their segments. The header and payload are base64url-encoded JSON, which is why anyone can decode a JWT and read its claims — the encoding is not encryption, as the next section explains.
Basic authentication. HTTP Basic Auth sends username:password as a Base64 string in the Authorization header. It looks scrambled, but it decodes instantly — which is why Basic Auth is only ever used over HTTPS.
Embedding binary data in JSON and XML. Neither format has a binary type. When an API needs to return a file, a hash, or an encrypted blob inside a JSON response, Base64 is the standard way to do it.
Base64 Is Encoding, Not Encryption (Don’t Store Secrets in It)
This is the most important thing to understand about Base64: it provides no security at all. Encoding is a change of representation, like writing a number in Roman numerals. Anyone who recognises the format can reverse it in seconds, with no key and no password. There is nothing secret about the alphabet — it is published in an RFC.
Encryption, by contrast, scrambles data with a key, and reversing it without the key is meant to be infeasible. Base64 has no key. A Base64 string is exactly as readable as the original data to anyone who bothers to decode it, which is one web search or one line of Python away.
So never “hide” a password, an API key, or personal data by Base64-encoding it. It is not hidden. It is just written in a different alphabet, the way ROT13 is not encryption either. If data needs to stay secret, encrypt it with a real algorithm and a real key — and if you then need to send the encrypted bytes through a text channel, Base64-encode the ciphertext. Encoding and encryption work together, but they are not the same job.

Try It: Encode and Decode Online
The fastest way to build an intuition for Base64 is to try it. The free Base64 encoder and decoder converts text in both directions in your browser: type Hello, get SGVsbG8=; paste TWFu, get Man. Try inputs of different lengths and watch the padding appear and disappear — one byte left over gives ==, two gives =, three gives none.
For images, the Base64 image converter turns an image file into a Base64 string (and a ready-to-paste data URI), or decodes a Base64 string back into an image you can download. That is the tool for the data-URI use case above.
If you are working in code instead, every major language has Base64 in its standard library: Python’s base64 module, JavaScript’s btoa and atob in browsers (or Buffer.from in Node), and Go’s encoding/base64 package. One gotcha in JavaScript: btoa only handles characters in the Latin-1 range, so non-English text needs to be converted to UTF-8 bytes first, or the call throws.

Frequently Asked Questions
What is Base64 encoding used for?
Carrying binary data through text-only systems: email attachments, images embedded in web pages as data URIs, binary fields inside JSON, and the segments of a JWT. Anywhere bytes need to travel as plain text, Base64 is the usual answer.
Why does Base64 end with = signs?
The = is padding. Base64 works in 3-byte chunks, and when the input length is not a multiple of 3, the last chunk is short. One leftover byte produces ==, two leftover bytes produce =. The padding tells the decoder how many real bytes the final group holds.
Is Base64 encryption?
No. Base64 is encoding — a reversible change of format with no key. Anyone can decode a Base64 string instantly. It hides nothing. Never use it to protect a password, a secret, or sensitive data.
How much bigger does Base64 make data?
About 33% bigger. Every 3 input bytes become 4 output characters, so the encoded size is the original size × 4 ÷ 3. A 300 KB file encodes to about 400 KB.