Formula: Base64 & Gzip Overhead Systems Engineering Formula
- rawBinaryKilobytes: Raw Binary Kilobytes (KB)
- gzipCompressionSavingsPct: Gzip Compression Savings Pct (%)
Compute Base64 4/3 byte expansion and HTTP/JSON payload transfer overhead.
The engine rounds the kilobyte figure up to a whole number of 3 KB blocks before multiplying by four, so any input up to 3 KB returns 4 KB. The correct answer for 1 KB is about 1.33 KB. Sizes that are exact multiples of 3 KB, like the 750 KB default, are calculated correctly. For small files, multiply by 4/3 yourself.
No. The expansion is a fixed 4/3 regardless of whether the bytes are a photo, a PDF or random noise, because Base64 never looks at what the bytes mean. File type matters only for compression. Already compressed formats barely shrink further, while raw text, uncompressed images and audio can shrink a lot, which changes the gzip saving you should enter.
Measure it on a real sample: encode the file, gzip the text, and compare sizes. For Base64 of already compressed media, expect a saving a little under the 25% default, since that is close to the theoretical limit. For compressible content the saving can be larger. Never enter more than 100%; the calculator will return a negative wire size.
Compare the limit with the Base64 figure, not the file size. A text column storing the default file needs room for 1,000 KB of characters, and Base64 uses only single-byte ASCII characters, so character count and byte count are the same. If the column has a fixed maximum, divide it by 4/3 to find the largest raw file that will fit after encoding.
It costs a third more bytes before compression, extra CPU to encode and decode, and extra memory on both ends. For small items, such as thumbnails or signatures, that is often acceptable for the simplicity of one JSON request. For large files, a multipart upload or a separate binary endpoint avoids the 4/3 expansion and the double buffering entirely.
It depends on the input length modulo 3. If the byte count divides by 3 exactly, there is no padding. One leftover byte produces two = signs, and two leftover bytes produce one. The padding is part of the 4 × ceil(n / 3) count, which is why that formula always gives a multiple of four.
TLS encryption does not compress, so it adds a small framing cost and removes nothing. HTTP/2 compresses headers but not bodies. Body compression only happens if the server applies gzip or Brotli content encoding, which is the step this calculator models with its savings percentage. Without that, the wire size is the full encoded size, 1,000 KB on the default.
Because all three presets use a 25% saving, and Base64 adds exactly a third. Multiplying 4/3 by 0.75 gives 1, so the wire figure always matches the input: 450 KB, 750 KB and 1,125 KB. Change the saving to see it move. At 0% the wire size equals the full encoded size.
Yes. Multiply the encoded length by 3/4, then subtract one byte for each = padding character at the end. A 1,000 KB encoded string decodes to 750 KB. This is handy when an API only reports the length of the Base64 field and you need the real file size to compare against a storage limit.
Brotli usually compresses text somewhat better than gzip, but on Base64 of already compressed data both face the same ceiling: they can only recover the two wasted bits per character. Expect similar wire sizes for media. On compressible content Brotli may give a higher saving, so enter the figure you measure rather than assuming the two are interchangeable.
The label is fixed text. On sizes that divide by 3 KB the overhead really is a third, such as 250 KB on the default. On other sizes the rounding problem makes it larger, and for very small inputs, such as 1 KB, the line shows 3 KB, three times the input. Trust the label only for multiples of 3 KB.
Browsers decode Base64 with built-in functions, but the whole encoded string has to be in memory first, so a large field delays rendering until it fully arrives. Images embedded as data URIs also cannot be cached separately from the page or stylesheet that holds them. For anything over a few kilobytes, a separate image request is usually lighter.
Start with the default: a 750 KB binary blob, perhaps an image or a PDF, that has to travel inside a JSON field. Base64 turns it into 1,000 KB of text. The overhead line reads 250 KB, which is the extra third that every Base64 payload carries. Then a 25% compression saving is applied to that text and the wire size comes out at 750 KB, back where it started.
That last figure is the one people misread. It does not mean Base64 was free. It means the assumed gzip saving happened to cancel the expansion almost exactly, and as a later section explains, that is close to the best gzip can do on encoded data that was already compressed. The 1,000 KB is still what your server builds in memory, what the client has to parse, and what gets stored if the JSON is written to a database or a log.
The fourth line, 0.98 MB, is simply the encoded size converted at two to the tenth kilobytes per megabyte. It is there for people who think in megabytes, and its rounding is covered further down.
Base64 reads input in groups of 3 bytes, which is 24 bits. It splits those 24 bits into four 6-bit pieces and maps each piece to one of 64 printable characters. So every 3 bytes of input become 4 bytes of output, a ratio of 4/3, or 33.3% more.
When the input length is not a multiple of 3, the last group is short. Standard Base64 pads it with = signs so the output is always a multiple of 4 characters. That is where 4 × ceil(n / 3) comes from. A 10-byte input has three full groups plus one leftover byte; ceil(10 / 3) is 4 groups, so the output is 16 characters, the last two of them padding.
Some encoders drop the padding, especially the URL-safe variant used in JSON Web Tokens. Without padding the length is ceil(4n / 3), so the 10-byte example would be 14 characters. For payloads in the hundreds of kilobytes the difference is at most two characters and can be ignored.
Nothing about this depends on the content. Random bytes, a JPEG, or a string of zeros all expand by the same 4/3. Only compression, applied before or after, can change the final size.
A quick mental check follows from this. Take the raw size, add a third, and you have the encoded size to within a few bytes. If a tool reports something far from that, either it is counting padding, line breaks or a wrapper, or it is rounding the way this calculator does on small inputs.
The formula is meant to work on bytes, but this calculator applies the ceiling to the kilobyte figure you type. For the default that makes no difference, because 750 divides by 3 exactly, and the same is true of the 450 KB and 1,125 KB presets. For other sizes it does.
Enter 10 KB and the result is 16 KB, where the true answer is about 13.3 KB. Enter 1 KB and it shows 4 KB, four times the input, with an overhead line of 3 KB that is plainly not 33.3%. Enter 4 KB and you get 8 KB. The engine is rounding the input up to the next 3 KB block before multiplying.
For large files the error is never more than 4 KB, so on the default scale it is negligible. For small payloads, such as an icon, a thumbnail or a signature image, it is badly wrong. Two workarounds: round your size to a multiple of 3 KB before entering it, or skip the calculator and multiply by 4/3 yourself, which is accurate to within a few bytes.
Base64 text uses only 64 different characters, so each 8-bit output byte carries just 6 bits of information. A general-purpose compressor such as gzip or Brotli can notice that and squeeze the text back down. In the ideal case it removes exactly the slack Base64 added: 6 bits out of 8 is 75% of the encoded size, which is a 25% saving.
That is why the default's 25% gives 1,000 KB × 0.75 = 750 KB, the original size. If the binary inside was already compressed, as JPEG, PNG, MP4 and ZIP files are, 25% is roughly the ceiling. In practice gzip usually gets somewhat less than that, because its Huffman coding does not reach the ideal exactly, so the real wire size tends to sit a little above the raw size.
Higher savings are only possible when the underlying data is itself compressible, such as an uncompressed bitmap, a WAV file or a block of text. Even then, compressing Base64 text works worse than compressing the raw bytes, because the encoding breaks byte boundaries and hides patterns from the compressor.
Be careful at the top of the range. The calculator accepts any percentage, and a saving above 100 gives a negative wire size. Anything you enter should come from compressing a real sample.
The calculator models one order: encode, then compress the text, which is what happens when a JSON body with a Base64 field is sent over HTTP with gzip content encoding. The other order is compressing the binary first and then encoding the compressed bytes, which is common when you control both ends and want the stored JSON itself to be small.
In that order the 4/3 expansion is applied to the compressed size, and nothing compresses the text afterwards, unless HTTP does so again. You can model it here by entering the compressed size as Raw Binary Kilobytes and setting the gzip saving to 0. Suppose compression first takes a 750 KB file down to 450 KB. Enter 450 and the encoded size is 600 KB, which is the Lower preset's answer.
Which order wins depends on the data. For already compressed media, neither order shrinks it much, and encode-then-gzip at least gets back to roughly the raw size on the wire. For compressible data, compressing the raw bytes first nearly always gives the smaller result, because gzip sees the real patterns instead of the encoded ones.
Because Base64 is a fixed ratio, the presets scale in a straight line. The Lower preset turns 450 KB into 600 KB, with a 150 KB overhead and a 450 KB wire size after the 25% saving. The Higher preset turns 1,125 KB into 1,500 KB, with a 375 KB overhead and a 1,125 KB wire size. In every case the overhead is a third of the input and the wire size equals the input, for the reason given above.
What changes in real systems is not the ratio but the limits you run into. Request body caps on API gateways and web servers are usually set on the encoded size, so a file that fits comfortably as binary can be rejected once it is Base64 inside JSON. Check your limit against the encoded figure, 1,500 KB for the Higher preset, not against the file size on disk.
Memory is the other cost. A server that decodes the JSON holds the encoded string and the decoded bytes at once, and often a copy of the parsed object as well. That is two or three times the file size for the lifetime of the request.
The MB line divides kilobytes by two to the tenth power, not by a round thousand, so 1,000 KB shows as 0.98 MB and 1,500 KB as 1.46 MB. That treats the input as binary kilobytes (KiB), and the output as binary megabytes. If your file size came from a tool that uses decimal kilobytes, 1000 bytes each, the encoded figure is still right in that same unit; only the MB conversion is off by about 2.4%.
Small inputs make this line useless. Anything under about 5 KB rounds to 0 MB or 0.01 MB, so read the KB figure instead.
For exact work, use bytes throughout. Convert your file size to bytes, apply 4 × ceil(n / 3), and divide at the end. That also sidesteps the rounding problem described above.
The 4/3 figure covers the encoded characters only. Several common wrappers add a little more.
MIME encoding for email inserts a line break every 76 characters, which adds two bytes per line, roughly 2.6% on top. PEM files for keys and certificates wrap at 64 characters and add a header and footer. A data URI in HTML or CSS needs a short prefix naming the media type. And inside JSON, some serializers escape the forward slash, one of the 64 Base64 characters, as a two-character sequence, which can add a few percent depending on the data.
URL-safe Base64 swaps + and / for - and _ so the string can go in a URL without percent-encoding. The length is the same as standard Base64, minus any padding the encoder drops.
None of these are modelled by the calculator. For most API payloads they are small next to the 250 KB overhead of the default, but for email attachments the line breaks are worth adding.