Base64 Encoder &
decoder.
Turn text or a file into Base64, or decode it, all inside your browser.
- Input bytes
- 13
- Groups of 3
- 5
- Padding
- 2 × =
13 bytes make 4 full groups of 3 and 1 byte over, so the last group ends with two = signs. The Base64 is 54% longer than the input; for long inputs the increase settles near a third.
Three bytes become four characters
Slide to any groupGroup 1 of 5: 3 bytes (48 65 6C), 24 bits, split into 6-bit values 18, 6, 21, 44, which write SGVs.
Every group
| Group | Bytes | Values | Base64 |
|---|---|---|---|
| 1 | 48 65 6C6-bit values 18, 6, 21, 44 | 18, 6, 21, 44 | SGVs |
| 2 | 6C 6F 2C6-bit values 27, 6, 60, 44 | 27, 6, 60, 44 | bG8s |
| 3 | 20 57 6F6-bit values 8, 5, 29, 47 | 8, 5, 29, 47 | IFdv |
| 4 | 72 6C 646-bit values 28, 38, 49, 36 | 28, 38, 49, 36 | cmxk |
| 5 | 216-bit values 8, 16 | 8, 16 | IQ== |
One line at a time
Turn this on to encode a list, such as user names or settings, one line each.
Encode a file
How it's worked out
Base64 writes any data with 64 safe characters: A to Z, a to z, 0 to 9, plus + and /. RFC 4648 sets the rules. The tool first turns your text into bytes with UTF-8, so an accented letter or an emoji survives the trip. The letter é, for example, is two bytes and comes out as w6k=.
Then it takes the bytes three at a time. Three bytes are 24 bits, and 24 bits split into four groups of 6. Each 6-bit group is a number from 0 to 63, and that number picks one character from the list.
The brackets mean "round up". When the last group is short, zero bits fill the gap and = signs mark the missing characters. One byte over gives two = signs and two bytes over give one: f is Zg==, fo is Zm8=, foo is Zm9v.
The URL-safe form swaps + for - and / for _, since + and / mean something in a web address. RFC 7515, used by JSON Web Tokens, also drops the = signs, so f becomes Zg. Decoding reverses every step, and the tool reads either alphabet, with or without padding.
Worked examples
Ana checks a short greeting group by group
Ana is learning how Base64 works. "Good morning." is 13 bytes, so it makes 5 groups. The first group is Goo, the bytes 47 6F 6F. Split into 6-bit values they are 17, 54, 61, 47, which pick R29v.
The last group holds only the full stop, one byte. Two zero bits round it up to two characters, and two = signs fill the rest, so it writes Lg==. The full answer is R29vZCBtb3JuaW5nLg==, which is 20 characters, 54% longer than the input.
Dev builds an HTTP Basic login header
Dev is testing an API that uses HTTP Basic login. The rule is to join the user name and password with a colon, then encode that. With the sample from the standard, Aladdin and open sesame, the 19 bytes become QWxhZGRpbjpvcGVuIHNlc2FtZQ==.
The header is then the word Basic, a space and that value. Anyone who sees the request can decode it in one step, which is why the standard calls the scheme not secure unless the connection is encrypted with HTTPS.
Lee reads the header of a JSON Web Token
Lee copies the first part of a token, the text before the first dot. It is 36 characters with no = signs, as tokens leave them off. It decodes to 27 bytes of text: {"alg":"HS256","typ":"JWT"}.
The alg field names the signing method the token uses. The other parts decode the same way, one at a time. If a part decodes to bytes that are not text, the tool shows them in hex instead.
Reading your result
The length grows by about a third. Every 3 bytes become 4 characters. A short input grows more, because the last group is always padded to 4: "Good morning." grew by 54%. A 1 MB file grows by 33.3%.
| Input | Base64 characters |
|---|---|
| 1 KB | 1,368 |
| 100 KB | 136,536 |
| 1 MB | 1,398,104 |
Line breaks add a little more. MIME email keeps lines to 76 characters, so a 100 KB attachment runs to 1,797 lines, each with its own line break. PEM files, such as certificates, use lines of exactly 64 characters between BEGIN and END lines.
Decoded bytes are not always text. If the bytes are not valid UTF-8, the tool shows them in hex. That usually means the Base64 held a file, such as a picture or a zip, or text saved in an older encoding.
A data URL puts a file inside a page. It starts with data:, the file type and ;base64, then the Base64 itself (RFC 2397). It saves one request for a tiny icon, but the extra third in size makes it a poor choice for large images.
Common mistakes
- Treating Base64 as a lock. It has no key. RFC 4648 says base encoding gives no confidentiality, so never use it to hide a password or private data.
- Mixing the two alphabets. A value with - or _ is URL-safe, and one with + or / is standard. Some decoders accept only one kind, so a token may fail in a tool that expects the other.
- Stripping the = signs and the length with them. Some decoders need the padding. If a value is refused, add = signs until its length is a multiple of 4.
- Encoding text in the wrong character set. This tool uses UTF-8, as the web does. Text saved in an older code page gives different bytes, so the Base64 will not match.
- Putting secrets in a share link. The tool keeps your text in the link fragment so that it opens again for you. Do not send a link that holds a token or a password.