Understanding Base64 Encoding
Base64 Encoding Process (3 bytes → 4 chars)
Base64 is a binary-to-text encoding scheme (defined in RFC 4648) that represents binary data using 64 printable ASCII characters. It groups every 3 bytes (24 bits) of input into 4 groups of 6 bits each, then maps each 6-bit value to a character in the Base64 alphabet (A-Z, a-z, 0-9, +, /).
Base64 Variants
| Variant | Chars 62–63 | Padding | Use Case |
|---|---|---|---|
| Standard (RFC 4648) | + / | = padding | MIME, email, file encoding |
| URL-Safe (RFC 4648 §5) | - _ | Optional | JWTs, URLs, filenames |
| Base64url (no padding) | - _ | None | OAuth 2.0, PKCE, OpenID |
| MIME (RFC 2045) | + / | 76-char lines | Email attachments |
Common Use Cases
- HTTP Basic Auth:
Authorization: Basic base64(user:password) - JWT Tokens: Each section (header/payload/signature) is Base64URL encoded.
- Data URLs:
data:image/png;base64,iVBOR...embeds images in HTML/CSS. - Email Attachments: MIME encoding transfers binary files over text-based SMTP.
- API Payloads: Encode binary blobs (images, PDFs) in JSON strings.