Base64 Encoding: What It Is, Why It Exists, and When to Use It
You see Base64 strings everywhere — in email attachments, data URLs, JWT tokens. But what IS Base64? Here's the complete explanation with practical examples.
Why Base64 Exists
Email was designed for text. HTTP was designed for text. JSON was designed for text. But sometimes you need to send an image, a PDF, or binary data through these text-only channels. That's what Base64 solves.
Base64 takes any binary data and converts it into a safe alphabet of 64 characters: A-Z, a-z, 0-9, +, and /. The result is ~33% larger than the original, but it can travel through any text-based system safely.
How Base64 Works (Simplified)
- Take binary data:
Hello→01001000 01100101 01101100 01101100 01101111 - Split into 6-bit groups:
010010 000110 010101 101100 011011 000110 1111 - Map each 6-bit group to a Base64 character
- Result:
SGVsbG8=
Common Base64 Use Cases
| Use Case | Example |
|---|---|
| Data URL (embed image in HTML) | <img src="data:image/png;base64,iVBOR..."> |
| Email attachment (MIME) | Content-Transfer-Encoding: base64 |
| JWT token payload | eyJhbGciOiJIUzI1NiJ9... |
| API binary upload | {"file": "JVBERi0xLjQ..."} |
Step-by-Step: Encode or Decode Base64
- Open the Base64 encoder/decoder
- Paste your text (to encode) or Base64 string (to decode)
- Click "Encode" or "Decode"
- Copy the result instantly
Base64 Gotchas
- Not encryption: Never use Base64 to "hide" sensitive data. It's trivially reversible.
- Size overhead: Base64 output is ~33% larger than the input. Don't use it for large files in production.
- URL safety: Standard Base64 uses
+and/which break URLs. Use "URL-safe Base64" which replaces them with-and_. - Padding: Base64 strings end with
=or==for padding. Some systems strip this — you may need to add it back.
Try it now: Encode/Decode Base64 →
Instant encoding and decoding. Works entirely in your browser.
Frequently Asked Questions
What is Base64 encoding?
Base64 is a method of converting binary data (images, files) into a text string using 64 ASCII characters (A-Z, a-z, 0-9, +, /). It's used to safely transmit binary data through text-only channels.
Is Base64 encryption?
No. Base64 is encoding, not encryption. Anyone can decode a Base64 string instantly. It provides zero security — it's purely a data format conversion for transmission compatibility.
When should I use Base64?
Use Base64 for: embedding images in HTML/CSS (data URLs), sending binary attachments in email (MIME), including binary data in JSON payloads, and storing binary data in text-based databases.