Base64 Encoder/Decoder
Encode and decode Base64 strings
Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters. It is used to safely transmit binary data through text-based protocols like email (MIME), HTML (data URIs), and HTTP headers. Base64 is encoding, not encryption — anyone can decode it.
What is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 ASCII characters. It was designed to ensure that binary data can be safely transmitted over text-based systems that may not handle raw bytes correctly — such as email (SMTP), JSON, XML, and URL parameters.
The name “Base64” refers to the 64-character alphabet used for encoding. Unlike hexadecimal (Base16), which uses 16 characters, Base64 is more compact — it represents 6 bits per character instead of 4.
How Base64 Encoding Works
The encoding process operates on groups of 3 bytes (24 bits) at a time:
- Take 3 bytes of input (24 bits total)
- Split into 4 groups of 6 bits each
- Map each 6-bit value to a character from the Base64 alphabet
- If the input length isn’t a multiple of 3, pad with
=characters
The Base64 Alphabet
| Index Range | Characters | Count |
|---|---|---|
| 0-25 | A to Z | 26 |
| 26-51 | a to z | 26 |
| 52-61 | 0 to 9 | 10 |
| 62 | + | 1 |
| 63 | / | 1 |
| Padding | = | — |
Base64URL Variant
For URLs and filenames, the standard + and / characters are problematic. The Base64URL variant (RFC 4648 §5) replaces them:
+becomes-/becomes_- Padding
=is often omitted
This variant is used in JWTs, OAuth tokens, and anywhere tokens appear in URLs.
Padding Explained
Base64 works on 3-byte groups. When the input doesn’t divide evenly by 3:
| Input Bytes | Base64 Output | Padding |
|---|---|---|
| 3 bytes | 4 characters | None |
| 2 bytes | 3 characters + = | 1 pad |
| 1 byte | 2 characters + == | 2 pads |
Common Use Cases
- Email attachments (MIME): Binary files are Base64-encoded to travel safely through SMTP, which only supports 7-bit ASCII
- Data URIs: Embed images directly in HTML or CSS as
data:image/png;base64,iVBORw0KGgo... - HTTP Basic Auth: The
Authorization: Basicheader carriesusername:passwordas Base64 - JSON payloads: Binary data (files, images, certificates) can be embedded in JSON strings via Base64
- JWT tokens: Each segment (header, payload, signature) is Base64URL-encoded
Try These Examples
Simple ASCII text encoded to Base64 produces 'SGVsbG8sIFdvcmxkIQ=='. The == padding indicates the input length wasn't a multiple of 3 bytes.
Hello, World! UTF-8 text with accented characters and emoji. Multi-byte characters produce longer Base64 output since each character may be 2-4 bytes.
Café ☕ résumé An empty input produces no output. Base64 encoding requires at least one byte of input data.