What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into ASCII string format using 64 printable characters (A-Z, a-z, 0-9, +, /). It's essential for encoding data that needs to be stored or transferred over text-based protocols like HTTP, email, JSON APIs, and XML.
When to Use Base64?
- Data URIs: Embed images in HTML/CSS without external files
- API Communication: Send binary data over JSON/XML APIs
- Authentication: HTTP Basic Auth encodes credentials
- Email Attachments: MIME uses Base64 for files
- JWT Tokens: JSON Web Tokens use Base64URL
- Certificates: PEM format uses Base64 for SSL certs
How Does It Work?
Base64 encoding works by: 1) Dividing input data into 3-byte groups (24 bits), 2) Splitting into 4 groups of 6 bits each, 3) Mapping each 6-bit value to a Base64 character, 4) Adding padding (=) if needed. Important: Increases data size by ~33%.