JSON Formatter โบ Guides
Does Base64 really make data 33% bigger? We measured it before and after compression
Most explanations of Base64 repeat the same figure: it makes data one third bigger. The figure is correct, but it describes the data before anything else happens to it. On the web, most text is compressed with gzip or Brotli on its way to the browser, and that changes the answer in both directions. We took eight files from this site, encoded each one, and measured the size at every step.
Short answer: Base64 added 33.3 to 33.4% to every file, and 36.8 to 37.3% with the line breaks that email uses. After gzip, a Base64 image was less than 1% bigger than the original image, so the cost almost disappeared. Text went the other way: Base64 text was 40 to 65% bigger than the same text compressed directly. Base64 is cheap for data that is already compressed and expensive for data that is not.
Where the 33% comes from
Base64 writes binary data using 64 safe characters: the letters A to Z and a to z, the digits, and two symbols. Sixty-four characters can carry 6 bits each, while a byte holds 8. So every 3 bytes of input (24 bits) become 4 characters of output, and 4 divided by 3 is 1.333. If the input length is not a multiple of 3, the last group is filled out with one or two = signs, which is why very short inputs grow by more than a third: a single byte becomes four characters.
You can watch this on our Base64 encoder. Type Hi and you get SGk=: two bytes in, four characters out.
What we measured
We used eight files that this site serves: five text files (an SVG icon, a stylesheet, a JSON list, an HTML page and a JavaScript library) and three WebP images from our guides. For each file we recorded the size of the original, of its Base64 form, and of both after gzip at its highest setting (level 9) and after Brotli at its highest setting (quality 11). The sizes were computed with Python's built-in base64 and gzip modules and Google's Brotli library. To tie the numbers to our own tool, we also pasted the five text files into the Base64 encoder on this site in Chromium and compared the output with the Base64 that Node.js produces for the same files: all five matched character for character.
| File | Original | Base64 | Growth |
|---|---|---|---|
| SVG icon | 354 bytes | 472 | +33.3% |
| Stylesheet (CSS) | 7,612 | 10,152 | +33.4% |
| JSON list | 17,227 | 22,972 | +33.3% |
| HTML page | 18,586 | 24,784 | +33.3% |
| JavaScript library | 56,694 | 75,592 | +33.3% |
| WebP image A | 13,956 | 18,608 | +33.3% |
| WebP image B | 25,380 | 33,840 | +33.3% |
| WebP image C | 34,620 | 46,160 | +33.3% |
No surprise so far. The kind of file makes no difference, because Base64 does not look at what the bytes mean.
After compression the picture splits in two
The next table compares what would actually travel over a compressed connection: the original file compressed, against the Base64 version compressed. The last two columns show how much bigger the Base64 route is.
| File | Original, gzip | Base64, gzip | Extra with gzip (%) | Extra with Brotli (%) |
|---|---|---|---|---|
| SVG icon | 242 | 343 | 41.7 | 58.0 |
| Stylesheet (CSS) | 2,275 | 3,747 | 64.7 | 81.9 |
| JSON list | 6,620 | 9,293 | 40.4 | 53.6 |
| HTML page | 5,044 | 7,803 | 54.7 | 81.6 |
| JavaScript library | 11,653 | 18,469 | 58.5 | 58.3 |
| WebP image A | 13,814 | 13,945 | 0.9 | 0.2 |
| WebP image B | 25,391 | 25,542 | 0.6 | -0.1 |
| WebP image C | 34,653 | 34,922 | 0.8 | -0.1 |
Images: the 33% almost vanishes. A WebP image is already compressed, so its bytes look almost random and gzip can barely shrink them (one became 1% smaller, the other two grew by 11 and 33 bytes). Its Base64 form, however, uses only 64 different characters, and a compressor can store each of them in about 6 bits instead of 8. That wins back nearly all of what Base64 added. With gzip the Base64 images ended up 0.6 to 0.9% bigger than the originals; with Brotli the difference was between -0.1% and +0.2%.
Text: the cost gets worse, not better. Text compresses well because it repeats itself: the same tag names, property names and words come back again and again. Base64 hides those repeats. The same word produces different characters depending on whether it starts at the first, second or third byte of a 3-byte group, so the compressor finds far fewer matches. Our stylesheet shrank to 2,275 bytes when gzipped directly, but to 3,747 bytes when it was Base64 first. In these five files the penalty was 40 to 65% with gzip and 54 to 82% with Brotli, well above the usual 33%.
If you must send text as Base64, compress it first
Sometimes a format only accepts text-safe characters and you have no choice. The order of the two steps then matters a great deal.
| File | Base64, then gzip | Gzip, then Base64 |
|---|---|---|
| Stylesheet (CSS) | 3,747 bytes | 3,036 |
| JSON list | 9,293 | 8,828 |
| HTML page | 7,803 | 6,728 |
| JavaScript library | 18,469 | 15,540 |
Compressing first and encoding second was 5 to 19% smaller in every case, and it keeps the cost at the predictable one third on top of the compressed size. The receiver has to reverse both steps in the opposite order.
Email adds a little more
Email attachments are usually sent as Base64 in lines of at most 76 characters, as the MIME standard requires; we broke the line after every 76 characters. Each break is two bytes, so the growth is closer to 37% than 33%: in our files it was 36.8 to 37.3%. Where a mail service counts its size limit after encoding, a 20 MB limit leaves room for about 14.6 MB of files. Mail is not usually compressed in transit the way web pages are, so here the full cost is paid.
What this means in practice
- Small images inlined as data URIs in HTML or CSS cost very little in transfer size when the page is served with gzip or Brotli: under 1% in our test. The real trade-offs are elsewhere. An inlined image cannot be cached on its own: it is downloaded again whenever the HTML page or stylesheet that holds it is downloaded, and the browser has to turn the Base64 back into bytes before it can read the image. Inlining suits small icons used on one page, not photos shared across a site.
- Inlining an SVG as Base64 is usually the wrong choice. SVG is text. It can go into a data URI with URL-encoding instead, or straight into the HTML, and then it compresses like the rest of the page.
- Binary data inside JSON is usually sent as Base64, because JSON has no binary type. If the data is already compressed (JPEG, PNG, WebP or ZIP, for example), a compressed connection takes back most of the overhead. If it is plain text or raw numbers, compress it before you encode it, or send it as a separate file.
- Stored Base64 pays full price unless the storage compresses it. Where a database column or a file on disk is kept uncompressed, a Base64 image takes the whole extra third. Some databases and file systems do compress what they store, and there the cost shrinks the way it did in our gzip test.
Limits of this test
Eight files from one site are a small sample. The exact penalty for text depends on how repetitive the text is and on the compressor settings; servers often use lower levels than the maximum we used, which changes the absolute sizes. The direction of the result follows from how Base64 and compressors work, so it should hold elsewhere, but measure your own files before making a decision that depends on a few percent. We measured the files as this site served them on 25 November 2026; they will change as the site changes.
The measurements are in files.csv: columns file, kind, raw_bytes, base64_bytes, base64_mime_wrapped_bytes, gzip_raw, gzip_base64, brotli_raw and brotli_base64, all in bytes.
Common questions
Is Base64 a kind of compression or encryption?
Neither. It makes data larger, and anyone can decode it without a key. Its only job is to carry bytes through places that accept plain text.
Does URL-safe Base64 change the size?
It swaps + and / for - and _, which does not change the length. Many URL-safe variants also drop the = padding, which saves up to two characters.
Why is my Base64 longer than 4/3 of my text length?
Base64 counts bytes, not characters. In UTF-8 an accented letter takes two bytes, a Korean syllable three and most emoji four, so text outside plain English has more bytes than characters before encoding starts.
References
- RFC 4648: The Base16, Base32, and Base64 Data Encodings
- RFC 2045: MIME Part One, section 6.8 (Base64 Content-Transfer-Encoding)
- MDN: data: URLs
- RFC 1952: GZIP file format specification
Figures without a source link come from the steps shown on this page. Companion tool: JSON Formatter. Spotted an error? Write to help@glowhalo.org. Chromium and Google are trademarks of their owners; GlowHalo is not affiliated with them.