Base64 Encoding: The Developer's Guide
Everything you need to know about Base64 encoding. Learn when to use it, how it works, and common pitfalls to avoid.
What is Base64?
Base64 is an encoding scheme that converts binary data into ASCII text format. It uses 64 characters (A-Z, a-z, 0-9, +, /) to represent data, making it safe to transmit through systems that only support text.
Example:
Hello World
→SGVsbG8gV29ybGQ=
Common Use Cases
API Data Transfer
Send binary data in JSON APIs where only text is allowed
Email Attachments
Embed files in emails using MIME encoding
Data URLs
Embed images directly in HTML/CSS without external files
Basic Auth Headers
HTTP Basic Authentication uses Base64 for credentials
How Base64 Works
- 1
Convert to binary
Each character becomes 8-bit binary (ASCII values)
- 2
Group into 6-bit chunks
Binary is regrouped from 8-bit to 6-bit segments
- 3
Map to Base64 characters
Each 6-bit value maps to a character in the Base64 alphabet
- 4
Add padding if needed
'=' characters pad the output to make it divisible by 4
Code Examples
JavaScript:
// Encode const encoded = btoa('Hello World') // Decode const decoded = atob('SGVsbG8gV29ybGQ=')
Python:
import base64 # Encode encoded = base64.b64encode(b'Hello World') # Decode decoded = base64.b64decode('SGVsbG8gV29ybGQ=')
Important to Remember
- ⚠️
Not encryption: Base64 is encoding, not encryption. Anyone can decode it.
- 📈
Size increase: Base64 increases size by ~33% due to the encoding overhead.
- ✓
URL-safe variant: Use URL-safe Base64 for URLs (replaces +/ with -_).
- 🔍
Character set: Only uses ASCII characters, safe for any text system.
Try Base64 Encoder/Decoder
Free online Base64 tool. Encode and decode text, files, and images instantly.
Try Base64 Tool