Overview
Base64 is a binary-to-text encoding scheme that represents binary data in ASCII string format. It uses a set of 64 characters (A-Z, a-z, 0-9, +, /) to encode binary data, with = used for padding. This encoding is essential for transmitting binary data over text-based protocols.
Technical Details
Character Set
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numbers (0-9)
- Special characters (+, /)
- Padding character (=)
Key Features
- ASCII compatible
- URL-safe variants available
- 33% size increase
- Widely supported
Common Uses
- Email attachments
- Data URLs in web pages
- Basic authentication
- Binary data in JSON
Examples
Basic Encoding
Original: Hello World! Base64: SGVsbG8gV29ybGQh Original: 😊 Base64: 8J+Yig==
Implementation
JavaScript Example
// Encoding
const text = "Hello World!";
const encoded = btoa(text);
console.log(encoded); // "SGVsbG8gV29ybGQh"
// Decoding
const decoded = atob(encoded);
console.log(decoded); // "Hello World!"