Base64 Encoding Demystified: What Every Developer Needs to Know
A practical deep-dive into Base64 encoding — how it works, why it's used, and how to encode/decode data properly. Includes real-world use cases like data URLs, JWT tokens, and API authentication.
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into an ASCII string format. It's not encryption (a common misconception) — it's encoding. Anyone can decode Base64 without a key.
The name "Base64" comes from the fact that it uses 64 different characters (A-Z, a-z, 0-9, +, /) plus the = padding character to represent binary data.
How Base64 Actually Works
Base64 processes data in 3-byte chunks:
Example:
The text "Man" converts to "TWFu" in Base64.
| Text | M | a | n |
|------|---|---|---|
| ASCII | 77 | 97 | 110 |
| Binary | 01001101 | 01100001 | 01101110 |
| 6-bit groups | 010011 | 010110 | 000101 | 101110 |
| Base64 | T | W | F | u |
Common Use Cases
1. Data URLs
Embed images directly in HTML/CSS:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...">
2. Email Attachments (MIME)
Email protocols are text-based. Base64 encodes binary attachments for transmission.
3. API Authentication
Basic Auth headers use Base64:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
4. JWT Tokens
JSON Web Tokens use Base64URL (a URL-safe variant) for their header and payload sections.
5. Storing Binary Data in JSON
JSON has no native binary type. Base64 encodes binary data as a string.
Important Security Note
**Base64 is NOT encryption.** Never use it to protect sensitive data:
Base64 vs Base64URL
Standard Base64 uses "+" and "/" characters that need URL-encoding in URLs. Base64URL replaces them with "-" and "_" respectively, making it safe for URLs without additional encoding.
Using Our Tools
Visit txt.tools for free Base64 encoding and decoding:
All processing happens in your browser. Your data stays private.
Performance Considerations
Base64 encoding increases data size by approximately 33%. This means:
Enjoyed this article?
Check out our free online tools at txt.tools to help you work faster and smarter.