Base64 Encoder & Decoder
Encode text/files to Base64 or decode back. Works with UTF-8 characters.
What is Base64?
Base64 is a way of representing binary data using only 64 printable ASCII characters. It exists because many systems - email, URLs, JSON, XML - were designed to carry text and mishandle arbitrary binary data.
It is an encoding, not encryption. Anyone can decode Base64 instantly, and it provides no confidentiality whatsoever. Its purpose is safe transport, not secrecy.
Key takeaways
- Base64 uses A-Z, a-z, 0-9, + and /, with = as padding.
- Encoded output is about 33% larger than the input.
- It is not encryption - decoding requires no key and takes milliseconds.
- URL-safe Base64 replaces + and / with - and _.
- Common uses: email attachments, data URIs, JWTs, and binary data in JSON.
How the encoding works
Base64 takes three bytes of input - 24 bits - and splits them into four groups of six bits. Each six-bit group indexes into a 64-character alphabet, producing four output characters.
- Take 3 input bytes: 24 bits total.
- Split into 4 groups of 6 bits.
- Map each 6-bit value (0-63) to a character in the Base64 alphabet.
- If the input is not a multiple of 3 bytes, pad the output with = signs.
Because 3 bytes become 4 characters, the output is always 4/3 the size of the input - roughly a 33% increase. This is the unavoidable cost of representing binary data in a text-safe form.
| Input | Length | Base64 output | Padding |
|---|---|---|---|
| Man | 3 bytes | TWFu | None |
| Ma | 2 bytes | TWE= | One = |
| M | 1 byte | TQ== | Two == |
| Hello | 5 bytes | SGVsbG8= | One = |
The = padding tells the decoder how many bytes of the final group were real data rather than zero-fill.
Base64 is not encryption
| Encoding (Base64) | Encryption (AES) | Hashing (SHA-256) | |
|---|---|---|---|
| Purpose | Safe transport | Confidentiality | Integrity / fingerprinting |
| Requires a key? | No | Yes | No |
| Reversible? | Yes, by anyone | Yes, with the key | No |
| Provides secrecy? | None at all | Yes | Not applicable |
Where Base64 is genuinely used
- Email attachments. MIME encodes binary attachments as Base64 because SMTP was designed for 7-bit text.
- Data URIs. Embedding a small image directly in CSS or HTML as
data:image/png;base64,...saves an HTTP request. - JSON Web Tokens. Each of the three JWT segments is URL-safe Base64.
- HTTP Basic authentication, which Base64-encodes the username and password - which is precisely why it must only be used over HTTPS.
- Binary data in JSON or XML, neither of which can carry raw bytes.
- Certificates and keys in PEM format, which wrap Base64 in header and footer lines.
Standard versus URL-safe Base64
Standard Base64 uses + and /, both of which have special meaning in URLs and would need percent-encoding. URL-safe Base64 substitutes them.
| Character | Standard | URL-safe |
|---|---|---|
| Index 62 | + | - |
| Index 63 | / | _ |
| Padding | = | Often omitted entirely |
JWTs use URL-safe Base64 without padding, which is why a JWT segment can be decoded by standard tools only after converting the characters back.
UTF-8 and non-English text
Base64 operates on bytes, not characters, so text must be converted to bytes first. For anything beyond basic ASCII, that conversion must be UTF-8 - and getting it wrong is the most common Base64 bug.
- A naive JavaScript
btoa()call throws an error on any character above U+00FF. - The correct approach encodes to UTF-8 bytes first, then Base64-encodes those bytes.
- This tool handles UTF-8 correctly, so emoji, accents and CJK text all round-trip cleanly.
Frequently Asked Questions
What is Base64 encoding?
A method of representing binary data using 64 printable ASCII characters - A to Z, a to z, 0 to 9, plus and slash. It exists so binary data can pass safely through systems designed to carry text, such as email, JSON and URLs.
Is Base64 encryption?
No, absolutely not. It has no key and no secret, and decoding it takes a single function call available in every language and every browser console. It provides no confidentiality at all - it is a transport format, not a security measure.
Why is Base64 output larger than the input?
Because three bytes of input become four output characters, making the result about 33 percent larger. That expansion is the unavoidable cost of representing arbitrary bytes using only a restricted set of text-safe characters.
What do the equals signs at the end mean?
They are padding. Base64 works in groups of three input bytes, so when the input length is not a multiple of three, one or two equals signs are added to tell the decoder how many bytes in the final group were real data.
What is URL-safe Base64?
A variant that replaces the plus with a hyphen and the slash with an underscore, because both original characters have special meaning in URLs. Padding is often omitted too. JSON Web Tokens use this variant.
Can Base64 handle emoji and non-English text?
Yes, provided the text is converted to UTF-8 bytes before encoding. This is the most common source of Base64 bugs - JavaScript's built-in btoa function fails on characters above U+00FF unless you encode to UTF-8 first. This tool handles it correctly.
Should I embed images as Base64 data URIs?
Only small ones. Embedding removes an HTTP request, which helps for tiny icons. For larger images it hurts: the file grows 33 percent, it cannot be cached independently, and it blocks rendering of the document containing it. A few kilobytes is a reasonable limit.
Why is HTTP Basic authentication considered insecure?
Because it merely Base64-encodes the username and password, which anyone intercepting the request can decode instantly. It is only acceptable over HTTPS, where the transport layer provides the actual protection.
Is my data sent to a server?
No. Encoding and decoding happen entirely in your browser. Nothing is transmitted, logged or stored.