Base64 Size Calculator
Calculate the exact size of Base64 encoded output for any input. Enter a file size to see the encoded length, padding characters, and overhead percentage.
Calculation Results
Original Size: ( bytes)
Encoded Size: ( characters)
Padding Characters:
Size Overhead: (%)
How Is Base64 Encoded Size Calculated?
The Base64 encoded size formula is ceil(input_bytes / 3) * 4. Every 3 input bytes are converted into 4 output characters. This produces a fixed overhead ratio of 4/3, which equals approximately 33.33% size increase. The formula accounts for padding: inputs not divisible by 3 are padded to the next multiple.
The formula works because Base64 reads 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each 6-bit group maps to one character from the Base64 character table. Since each output character occupies 1 byte in ASCII, 3 input bytes always become 4 output bytes. The table below shows calculated sizes for common input values.
| Original Size | Encoded Size | Overhead | Padding |
|---|---|---|---|
| 1 byte | 4 characters | 300% | == |
| 2 bytes | 4 characters | 100% | = |
| 3 bytes | 4 characters | 33.3% | none |
| 100 bytes | 136 characters | 36% | = |
| 1 KB (1,024 bytes) | 1,368 characters (1.34 KB) | 33.6% | varies |
| 10 KB (10,240 bytes) | 13,656 characters (13.34 KB) | 33.4% | varies |
| 100 KB | 136,536 characters (133.3 KB) | 33.3% | varies |
| 1 MB (1,048,576 bytes) | 1,398,104 characters (1.33 MB) | 33.3% | varies |
Why Does Base64 Increase File Size by 33%?
Base64 increases size by 33% because it encodes 3 bytes (24 bits) into 4 characters (32 bits). Each input byte contains 8 bits, but each Base64 character represents only 6 bits. The ratio is 4 output bytes divided by 3 input bytes = 1.333, which is a 33.33% increase. This overhead is a mathematical constant of the encoding design.
The 6-bit character width is the root cause. The Base64 alphabet contains 64 characters (2^6 = 64), so each character carries 6 bits of information. To encode a full byte (8 bits), Base64 needs more than 1 character. The least common multiple of 6 and 8 is 24, which is why Base64 processes data in 3-byte (24-bit) blocks. This 24-bit block divides evenly into four 6-bit groups and three 8-bit bytes.
When Does Base64 Size Overhead Exceed 33%?
Base64 overhead exceeds 33% for inputs smaller than 3 bytes and when MIME line breaks are added. A 1-byte input becomes 4 characters (300% overhead). A 2-byte input becomes 4 characters (100% overhead). The 33.33% ratio is only reached at exactly 3 input bytes and asymptotically approached for larger inputs.
MIME encoding (RFC 2045) inserts a CRLF line break (2 bytes) after every 76 characters of Base64 output. This adds approximately 2.6% overhead on top of the 33.33% Base64 expansion. For a 1 MB file, MIME encoding produces approximately 1.37 MB of output instead of 1.33 MB. The total overhead is approximately 36.5% compared to the original binary.
Data URIs add further overhead from the MIME type prefix. The string data:image/png;base64, adds 22 characters before the Base64 data. For a 100-byte image, this prefix increases total overhead by 22%. For a 1 MB image, the prefix overhead is negligible (0.002%). Use the Base64 embed generator to create data URIs with the correct prefix.
How Does Base64 Size Affect Web Performance?
Base64 encoding increases data transfer size by 33%, which directly impacts page load time and bandwidth consumption. A 10 KB image served as a binary file requires a separate HTTP request but transfers 10 KB. The same image inline as Base64 eliminates the HTTP request but adds 13.3 KB to the HTML or CSS payload.
The performance tradeoff depends on image size. For images under 10 KB, the saved HTTP request often outweighs the 33% size increase. For images over 10 KB, serving separate binary files with HTTP/2 multiplexing is more efficient. Gzip compression reduces Base64 overhead in transit: Base64 text compresses well, typically recovering 15-25% of the overhead. See the Base64 vs binary comparison for detailed benchmarks.
Use the Base64 image encoder to convert small icons and logos to inline Base64. For CSS sprites and larger assets, serve them as binary files. The Base64 validator can verify encoded strings before embedding them in production HTML.
Frequently Asked Questions
What is the formula for Base64 encoded size?
The formula is ceil(n / 3) * 4, where n is the number of input bytes. This rounds up to the nearest multiple of 3 and multiplies by 4/3 to account for the 6-bit-per-character encoding. For example, 100 input bytes produce ceil(100/3) * 4 = 34 * 4 = 136 Base64 characters.
How much larger is a Base64 encoded image?
A Base64 encoded image is approximately 33.33% larger than the original binary file. This overhead is constant for any input size of 3 bytes or more. A 50 KB JPEG becomes approximately 66.7 KB in Base64. A 1 MB PNG becomes approximately 1.33 MB. The exact encoded size can be calculated with ceil(bytes / 3) * 4.
Does MIME Base64 add additional overhead?
Yes. MIME Base64 encoding (RFC 2045) inserts a CRLF line break (2 bytes) after every 76 characters. This adds approximately 2.6% extra overhead. The total size increase for MIME-encoded Base64 is approximately 36.5% compared to the original binary, versus 33.33% for standard Base64 without line breaks.
What is the maximum Base64 string size browsers can handle?
Modern browsers (Chrome, Firefox, Safari, Edge) can handle Base64 strings exceeding 2 GB, limited by available system memory. The atob() and btoa() functions process strings up to several hundred megabytes. Data URIs in <img> tags work up to browser-specific memory limits. For production use, inline Base64 images should be kept under 10 KB.
Does URL-safe Base64 have the same size as standard Base64?
URL-safe Base64 (RFC 4648 Section 5) produces the same number of encoded characters as standard Base64 when padding is included. When padding is omitted, the output is 0, 1, or 2 characters shorter depending on the input length modulo 3. The size difference is at most 2 bytes. Use the URL-safe Base64 encoder to compare output lengths.
Related Base64 Tools
- What is Base64? - Learn the fundamentals of Base64 encoding
- Base64 Character Table - Complete alphabet reference with index values
- Base64 Algorithm - Step-by-step encoding and decoding process
- Base64 Image Encoder - Convert images to Base64
- Base64 vs Binary - Compare encoding methods for web delivery
- Base64 Validator - Verify Base64 string correctness
- Base64 Embed Generator - Create data URI embeds
- All Base64 Tools - Browse the complete toolset