Base64 is a binary-to-text encoding scheme that encodes binary data by treating it numerically and translating it into a base-64 representation. The name comes from the 64 ASCII characters used: A-Z, a-z, 0-9, +, and /.
Why Base64 Exists
Many systems were designed to handle only text. Email protocols (SMTP), HTTP headers, and HTML attributes all expect plain text. Base64 allows binary data (images, files, certificates) to be safely embedded in text-based systems without corruption.
Common Use Cases
- Embedding images in HTML/CSS as data URLs
- Encoding email attachments (MIME)
- Storing binary data in JSON
- Basic authentication headers in HTTP
- Encoding cryptographic keys and certificates
Base64 in JavaScript
// Encode
const encoded = btoa("Hello, World!");
// Decode
const decoded = atob(encoded);Base64 vs Encryption
This is a critical distinction. Base64 is encoding, not encryption. Anyone can decode a Base64 string with zero effort. Never use Base64 to hide passwords or sensitive data — use proper encryption instead.