RFC 4648 Base64 Encoding Mathematics & Data URI Structure
Base64 maps 3 binary bytes (24 bits) into 4 printable ASCII characters (6 bits each) across a 64-character alphabet:
1. Base64 3-to-4 Byte Expansion Ratio
Expansion Ratio =
4 ASCII Characters (24 bits)3 Binary Bytes (24 bits)
= 1.333 ⟹ +33.33% Size Overhead2. RFC 2397 Data URI Specification
URI = "data:" + MIME + ";base64," + Data
Step-by-Step Base64 Decoding & Reconstruction Breakdown
Step 1: MIME Header Detection & Padding Validation
Inspect prefix for
data:image/(png|jpeg|webp|svg+xml);base64, and strip whitespace.Step 2: 6-Bit Word Unpacking & Binary Byte Reassembly
Convert every 4 ASCII indices into 3 octets:
(C1 << 18) | (C2 << 12) | (C3 << 6) | C4.Step 3: Binary Blob Creation & Graphic Canvas Render
Reconstructed Image=Rendered Bitmap / Vector Asset
Base64 Inlining vs External HTTP Asset Tradeoffs
| Metric | Base64 Inlined Asset | External Image File | Recommended Decision |
|---|---|---|---|
| HTTP Roundtrips | 0 extra network requests | 1 separate HTTP GET request | Inline small icons (<5 KB) |
| Payload Size | +33.3% larger transfer size | Original binary size | Use external for large photos |
| Browser Caching | Tied to HTML / CSS cache | Independently cached by URL | Use external for recurring logos |