How much bigger is a Base64 image?
Published 2026-11-10 · measured, not estimated, on the site's own assets
Base64 makes a file bigger. That much is common knowledge, and it is usually where the conversation stops. What rarely gets measured is how much bigger the payload is by the time it leaves your server, and whether that difference should influence how you ship an image at all.
So we encoded five of this site's own assets and compressed both the original file and its Base64 text with gzip at level 9, the way an ordinary static host would. The gap is far smaller than the familiar one-third figure suggests. The thing that actually costs you when you inline an image turns out to have nothing to do with byte count.
Why the raw overhead is exactly one third
Base64 exists to push binary data through channels that only carry text. The encoder takes every
three bytes of input — 24 bits — and chops them into four groups of six bits. Each six-bit value
maps to one character from a 64-symbol alphabet: A–Z, a–z,
0–9, plus + and /.
Four characters to carry three bytes. That ratio is 4/3, or 133.3% of the input, and it is where the 33% comes from. There is no setting to tune and no library that does better — the expansion is arithmetic, not an implementation detail.
Two small things push the real figure slightly past one third:
- Padding. When the input length is not divisible by three, the encoder emits
one or two
=characters to complete the last group. A 9,458-byte icon becomes 12,612 characters rather than the 12,611 the pure ratio predicts. - Line wrapping. MIME-style encoders insert a line break every 76 characters.
Browser APIs such as
btoaandFileReader.readAsDataURLdo not wrap; most mail libraries and CLI tools do, and the breaks are extra bytes that carry no data.
Treat 33% as a floor. What you paste into an HTML file is normally a hair above it.
The five files we measured
All five are real assets served by this site, in the formats they are served in. Sizes are raw byte lengths of the strings, before any HTTP layer touches them.
| File | Raw bytes | Base64 bytes | gzip(raw) | gzip(Base64) | gzip overhead |
|---|---|---|---|---|---|
| favicon.ico | 9,458 | 12,612 | 9,414 | 9,513 | +1.1% |
| apple-touch-icon.png | 10,916 | 14,556 | 10,939 | 11,044 | +1.0% |
| icon-192.png | 11,802 | 15,736 | 11,825 | 11,926 | +0.9% |
| icon-512.png | 32,932 | 43,912 | 32,545 | 33,076 | +1.6% |
| og-image.png | 68,848 | 91,800 | 66,981 | 68,068 | +1.6% |
Read the second and third columns and the 33% is intact: 9,458 becomes 12,612, 68,848 becomes 91,800. Read the last column and it is gone. After compression, inlining these files costs between 0.9% and 1.6% — a few dozen to a thousand bytes, depending on the file.
One note on the row count: icon-512.png and logo.png are the same bytes
on this site, so only one of them appears here. Measuring both would have produced two identical
rows and no extra information.
Where the 33% goes under compression
PNG and JPEG are already compressed containers. The pixel data has been through DEFLATE once before you ever see the file, so a second pass finds very little — for the icons above, gzip shaves off somewhere between a few bytes and a few hundred. There is no redundancy left to exploit.
Base64 text behaves differently. The encoded stream uses only 64 of the 256 possible byte values,
which means roughly two bits in every byte carry no information. A general-purpose compressor
spots that immediately and codes the symbols back down toward their actual entropy. That is why
gzip(Base64) lands within a couple of percent of gzip(raw): the transport
layer has effectively undone the expansion for you.
It does not undo all of it. Some residue survives — a thousand-odd bytes on the 68 KB image — and the residue grows with file size. But the headline is that 33% is a property of the string, not of the request.
Two conditions have to hold for this to be true. Compression has to be enabled for the response that carries the HTML, and it has to be applied to the document rather than skipped because the content type looks binary. Most hosts and CDNs do the right thing by default; a few disable compression above a size threshold, which is exactly where the overhead stops being free.
The costs that are not bytes
If the wire penalty is around 1%, then byte count is almost never the reason a data URI hurts. These are the reasons.
A data URI has no cache entry of its own
An image referenced by URL gets its own slot in the HTTP cache: an ETag or Last-Modified, a
Cache-Control lifetime, possibly immutable. The browser can revalidate
with a conditional request and receive a bodyless 304. A data URI has none of that. Its bytes live
inside the document, so its lifetime is the document's lifetime. Every fetch that misses the HTML
cache ships the image again — not as a 304, as payload.
Repetition multiplies what caching would have divided
An avatar used in twenty places on one page is twenty copies of the same string if you inline it twenty times. As a file it is one download and nineteen cache hits. The per-copy overhead is small; the multiplication is not.
The preload scanner cannot prioritize it
Browsers speculatively scan raw HTML for resource references before the parser finishes, so a
normal <img src> starts downloading in parallel with CSS and JavaScript. A data
URI offers nothing to fetch — the bytes still have to arrive as part of the document and then be
decoded. Meanwhile the document itself got bigger, so it arrives later and delays everything
queued behind it.
Any edit to the image invalidates the page
Change one pixel in an inlined icon and the HTML changes. Its ETag changes, its content hash changes, and every visitor re-downloads the whole document — markup, text, and every other inlined asset — to pick up a file that could have been a single small request. With a separate file you rename it or bump a query string and only that file is refetched.
When one third is genuinely irrelevant
There are cases where none of the above applies and the arithmetic is the only consideration:
- A favicon or a tiny icon used once. A 9 KB file at +1% is under a hundred bytes. The request it replaces would have cost more in latency than the bytes cost in bandwidth.
- Self-contained deliverables. A single-file HTML report, a demo you email to someone, a document that must render offline in five years — self-containment is the requirement, and the caching argument does not apply to a file that is opened once.
- Content that is unique per request. A generated chart or a rendered receipt that no two visitors share has no cache value to lose.
- Images small enough that the document stays under one congestion window. If the whole page is a few kilobytes, the extra bytes never become the bottleneck.
Everything else — a logo repeated across a site, a hero photograph, an icon set — belongs in a file. The favicon guide is a good example of the case where inlining genuinely wins.
Plan with numbers, not with the 33% rule
The honest planning question is not "how much bigger does Base64 make this" but "how many bytes does this page carry, and how often does it change". The Base64 image size calculator gives you the first half in one step: drop a file in and read the encoded length before you commit to pasting it. For the second half, the decision framework in when not to inline images walks through caching, reuse, and rendering cost in the order they usually bite.
How these numbers were produced
Each asset was read as bytes and encoded with Python's base64.b64encode. Both the
original bytes and the encoded text were then compressed with gzip.compress at
compresslevel=9, and every figure in the table is the length of the resulting byte
string. No HTTP layer is involved: no chunked transfer encoding, no CDN re-compression, no
content negotiation. The files are the ones this site serves, at the sizes it serves them.
That makes the table reproducible in a dozen lines of Python on any machine, which is the point. The 33% is a constant you can derive on paper; the 1% is what your users actually pay, and it depends on whether compression is on.
When to use it, when to skip it
Inline when:
- The image appears once, is small, and is needed on first paint.
- The deliverable must be a single self-contained file.
- The image is generated per request and has no cache value.
- You are targeting an environment where a second request is expensive or impossible.
Keep it as a file when:
- The same image appears more than once on a page or across pages.
- The image is large, or is a hero/LCP candidate.
- The image changes on a different schedule than the page around it.
- You need per-image caching, CDN delivery, format negotiation, or analytics.
The size penalty is real but small. The caching penalty is real and permanent. Design around the second one.