The Radix-64 Encoding Mathematics & RFC 2397
Computer networks originally prioritized 7-bit ASCII text transmission (such as early SMTP email protocols). Transmitting raw 8-bit binary image data through text-only gateways risked severe byte corruption whenever control codes (like line feeds or null bytes) were encountered.
Base64 solves this by taking 24 bits of binary data (three 8-bit bytes) and splitting them into four 6-bit numbers (sextets). Each 6-bit index (from 0 to 63) maps directly to a safe, printable ASCII character:
3 Binary Bytes (24 bits) → 4 Base64 Characters (32 bits) = +33.3% Payload Overhead
Under RFC 2397, prepending the data protocol header data:[<mediatype>][;base64],<data> instructs browser rendering engines to parse the textual payload as a direct binary resource.
Engineering Trade-Offs: When to Inline vs. Link
| Implementation | HTTP Requests | Browser Cacheability | Recommended Scenario |
|---|---|---|---|
| Inline Base64 Data URI | 0 (Zero extra requests) | Tied to parent HTML/CSS | Micro-icons (<3 KB), critical above-the-fold UI spinners, email newsletter logos. |
| External Linked Asset | 1 per image file | Independently cached (HTTP 304) | Hero photographs, e-commerce catalog images, banners (>10 KB). |