Base64 Payload Binary Inflation

Base64: turning 3 bytes into 4 characters since 1987. Every JSON API, data URI, and email attachment pays this ~33% tax. Put in your raw binary size. See what actually goes over the wire.

📦 Binary Payload Size

3 input bytes → 4 output Base64 characters. Always. Your 10 MB binary blob becomes ~13.3 MB inside JSON. Embedding images in API responses? This math matters. Measure the damage before your payloads balloon.

Base64 Encoding: Every 3 Bytes Become 4 Characters — 33% Size Inflation

Base64 is the universal binary-to-text encoding scheme used across HTTP APIs, email attachments (MIME), JSON payloads, data URIs, and certificate chains. Its fundamental trade-off is size: every 3 bytes of raw binary data expand into 4 Base64 characters, producing a predictable 33.33% size increase. When embedding a 12 MB binary asset as a Base64 string inside a JSON API response, the encoded payload balloons to approximately 16 MB — before accounting for the JSON wrapper, MIME type prefix, and transport encoding overhead.

The 3-to-4 Byte Encoding Rule

Base64 operates by dividing the input byte stream into 6-bit groups and mapping each group to a character in a 64-symbol alphabet (A–Z, a–z, 0–9, +, /). Three 8-bit bytes (24 bits) produce exactly four 6-bit groups, hence four Base64 characters. The encoding is deterministic and stateless, which is why the 4/3 = 1.333× inflation factor is universal. For sizes not divisible by 3, padding with = characters fills the remainder, adding negligible overhead.

Why You Should Avoid Base64 for Large Files

Embedding large binary assets as Base64-encoded strings inside JSON APIs or data URIs has compounding costs: the 33% encoding inflation, the loss of binary-efficient transport (no streaming, no range requests), increased memory pressure on JSON parsers, and the CPU cost of encode/decode operations at both ends. For files above a few hundred kilobytes, presigned URLs (e.g., AWS S3 presigned GET URLs, GCP signed URLs) are the industry-standard alternative — they provide time-limited direct access to the binary asset without bloating the API response body.

Data URI Overhead

A data URI of the form data:image/png;base64,... includes both the Base64-encoded payload and a MIME type prefix (typically 20–30 bytes). For a 12 MB raw file, the total data URI is approximately 16 MB (encoded) + negligible prefix, but the real cost is in browser memory and DOM size: a single data URI of this magnitude can freeze a web page's parser and consume hundreds of megabytes of decoded memory in the rendering pipeline. Modern web performance budgets cap data URIs at a few kilobytes for icons and tiny assets only.