RFC 4648 Mathematical Specification & Bit Expansion
Base64 partitions input byte streams into 6-bit slices (2⁶ = 64 combinations). Because 3 octets (3 × 8 = 24 bits) correspond exactly to 4 Base64 characters (4 × 6 = 24 bits), the resulting payload expands by 33.33%.
1. Encoded Output Length Formula
Output Length (bytes)=
4 × ⌈
N_input_bytes3
⌉2. Theoretical Bandwidth Inflation
Inflation Ratio==≈ +33.33%
4 characters × 6 bits3 octets × 8 bits
43
Step-by-Step Base64 Encoding Breakdown (Example: "Man")
Step 1: Convert ASCII Characters to 8-bit Binary Octets
'M' (77) = 01001101, 'a' (97) = 01100001, 'n' (110) = 01101110
Concatenated: [ 01001101 01100001 01101110 ] (24 bits)
Step 2: Partition into 4 Groups of 6 Bits
010011 (19) → 'T'
010110 (22) → 'W'
000101 (5) → 'F'
101110 (46) → 'u'
Step 3: Final Output Assembly
Encoded Base64 String=TWFu
Base64 vs URL-Safe Variant Reference
| Specification | Index 62 Character | Index 63 Character | Padding Policy | Standard Usage |
|---|---|---|---|---|
| RFC 4648 (Standard) | + | / | Mandatory '=' | MIME email, Data URIs, XML payloads |
| RFC 4648 §5 (URL-Safe) | - | _ | Optional / Omitted | JSON Web Tokens (JWT), Query params |