Email attachments, data URLs and login tokens all carry binary data as plain text, and that's what a Base64 encode and decode tool is for: it turns any data into letters, digits and a few symbols, and back again. Type in either box above to encode text to Base64 or decode Base64 to text, with every 6-bit group shown. Below is how Base64 works bit by bit, why it ends with = signs, and where you'll run into it.
What Base64 is
Base64 represents binary data using only 64 printable characters. Many systems, like email, JSON, XML and URLs, were built for text and can mangle raw bytes, so Base64 gives a safe way to carry images, files, keys and other binary data through them. The name comes from the alphabet size: 64 is 2⁶, so each Base64 character carries exactly 6 bits. The standard alphabet is:
| Values | Characters |
|---|---|
| 0–25 | A–Z |
| 26–51 | a–z |
| 52–61 | 0–9 |
| 62 | + |
| 63 | / |
How Base64 encoding works
Base64 works on groups of 3 bytes. Three bytes are 24 bits, and 24 bits split evenly into four groups of 6. Each 6-bit group is a number from 0 to 63, and that number picks a character from the alphabet. Take Man. Its bytes are 77, 97 and 110, or 01001101 01100001 01101110. Regrouped in sixes, that's 010011 010110 000101 101110, which is 19, 22, 5 and 46, and those values are the characters T, W, F and u. So Man encodes to TWFu. Text is first turned into UTF-8 bytes, so emoji and accented letters work too: 👋 encodes to 8J+Riw==. The text to binary converter shows the bytes of any text.
Why Base64 ends with = or ==
When the data isn't a multiple of 3 bytes, the last group is short. The encoder adds zero bits to fill the final 6-bit value, and then adds = signs so the output is still a multiple of 4 characters. One leftover byte gives two characters and ==, and two leftover bytes give three characters and =:
Man→TWFuMa→TWE=M→TQ==
The padding carries no data, so many systems leave it out. This tool decodes Base64 with or without it, and the Padding switch controls whether the encoder adds it.
Decoding Base64 by hand
Decoding runs the same steps backwards. Look up each character's value, write the values as 6-bit groups, join them, and read the bits back in groups of 8. TWFu is 19, 22, 5 and 46, which gives 010011 010110 000101 101110, or the bytes 77, 97 and 110: Man. With padding, the extra zero bits are thrown away. TQ== is 19 and 16, or 010011 010000. The first 8 bits, 01001101, are 77, the letter M, and the last four zeros were only padding.
Base64 makes data about 33% bigger
Every 3 bytes of input become 4 characters of output, so Base64 is 4/3 the size of the original, roughly a third larger. A 1 MB image becomes about 1.33 MB of Base64. That's the price of making binary data safe for text channels, and it's why large files are usually sent as real attachments or downloads rather than inlined as Base64.
URL-safe Base64
Two characters of the standard alphabet, + and /, have special meanings in URLs and file names. URL-safe Base64, also called Base64URL, swaps them for - and _ and usually drops the padding. In that form 👋 becomes 8J-Riw. JSON Web Tokens (JWTs) use it: the header {"alg":"HS256","typ":"JWT"} encodes to eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9, which is why so many tokens start with eyJ. This decoder accepts both alphabets.
Where you'll see Base64
- Data URLs. Small images can be embedded in HTML and CSS as
data:image/png;base64,…. Every PNG starts withiVBORw0KGgo, the Base64 form of its 8-byte signature. - Email attachments. MIME encodes attachments in Base64 so they survive mail servers built for text.
- HTTP Basic authentication. The browser sends
user:passasdXNlcjpwYXNz. That's why Basic auth must only be used over HTTPS. - Keys and certificates. PEM files wrap Base64 between lines like
-----BEGIN CERTIFICATE-----.
Base64 isn't encryption
Base64 has no key and no secret. Anyone can decode it in a second, as this page shows, so it hides nothing. Use it to transport data, and use real encryption, like TLS or AES, to protect it.
Troubleshooting Base64
- Line breaks and spaces in pasted Base64 are ignored, so wrapped email or PEM text decodes fine.
- If the decoded result isn't valid UTF-8, the data is probably binary, like an image or a compressed file, rather than text.
- To see the same bytes in hex or binary, use the hex converter or the binary translator.
Keep one size rule in mind: Base64 output is about four-thirds the size of the input, so a 3 MB file becomes roughly 4 MB of text.