What is Base64 Encoding? How It Works & When to Use It (2026)
Published April 2, 2026
Base64 is one of those technologies you use every day without realizing it. Every email attachment, every data: URL in CSS, and many API tokens use Base64 encoding. But what exactly is it?
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data (bytes) into ASCII text using 64 printable characters: A-Z, a-z, 0-9, +, and /. The = character is used for padding.
The name "Base64" comes from the fact that it uses a base-64 number system — each character represents 6 bits of data (2^6 = 64 possible values).
How Base64 Works
Base64 takes 3 bytes (24 bits) of binary data and converts them into 4 ASCII characters:
Input: "Hi!" (3 bytes: 72, 105, 33)
Binary: 01001000 01101001 00100001
Groups: 010010 000110 100100 100001
Index: 18 6 36 33
Chars: S G k h
Output: "SGkh"
Key Properties
- Output is ~33% larger than input (3 bytes → 4 characters)
- Output is safe for text-based protocols (email, HTTP, JSON)
- Encoding is reversible (no data loss)
- It is NOT encryption — anyone can decode it
Common Uses of Base64
1. Email Attachments (MIME)
Email protocols only support text. Base64 encodes binary files (images, PDFs) into text that can be transmitted via email. Every attachment you send uses Base64 under the hood.
2. Data URLs in CSS/HTML
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...">
This embeds small images directly in HTML/CSS, eliminating extra HTTP requests.
3. API Authentication Tokens
HTTP Basic Auth sends credentials as Base64(username:password). JWT tokens also use Base64 for their header and payload sections.
4. JSON Web Tokens (JWT)
JWT Structure: header.payload.signature
Each part is Base64URL encoded (uses - and _ instead of + and /)
5. Storing Binary Data in JSON
JSON can only contain text. Base64 lets you embed binary data (images, files) inside JSON responses.
Base64 vs Encryption
| Property | Base64 | Encryption |
|---|---|---|
| Purpose | Format conversion | Security |
| Key needed? | No | Yes |
| Reversible? | Yes (by anyone) | Only with key |
| Security | None (it's encoding) | Strong (AES, RSA) |