Home › Developer & IT › Base64 Size Calculator
Base64 Size Calculator
Computes the length of the Base64 encoding of a given number of bytes (4 characters per 3 bytes, padded with =), the 33 % overhead, the size with MIME/PEM line breaks and the length of a data: URI.
When to use
You need to know how large a file becomes when embedded as Base64 in JSON, email (MIME) or a data URI, or how many bytes a Base64 string decodes to.
Do not use when: You need to actually encode or decode data, or you are sizing Base32/Base16 output (8 characters per 5 bytes, 2 per byte).
Formula
encoded = 4 × ceil(size_bytes / 3); padding = (3 − size_bytes mod 3) mod 3; lines = ceil(encoded / line_length); with_breaks = encoded + 2 × lines; data_uri = encoded + length('data:' + mime_type + ';base64,')
RFC 4648 section 4 Base64 with = padding; MIME (RFC 2045) wraps at 76 characters with CRLF line endings, PEM at 64. Unpadded variants (base64url in JWTs) are shorter by padding_characters.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
size_bytes | integer | bytes | yes | Number of bytes before encoding. Range: ≥ 0, ≤ 1000000000000000 |
line_length | integer | characters | default 0 | Characters per line when the output is wrapped (76 for MIME per RFC 2045, 64 for PEM); 0 = single line without breaks. Range: ≥ 0, ≤ 1000 |
mime_type | string | default image/png | Media type written into the data: URI prefix (data:<mime>;base64,). |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
encoded_characters | integer | characters | 4 × ceil(size_bytes / 3) characters including padding. |
padding_characters | integer | Number of trailing = characters (0, 1 or 2). | |
overhead_percent | number | % | (encoded − raw) / raw × 100; tends to 33.33 % for large inputs. |
encoded_with_line_breaks | integer | characters | Encoded length plus a CRLF (2 characters) after every line of line_length characters; equals encoded_characters when line_length = 0. |
line_count | integer | Number of lines when wrapped (1 when not wrapped). | |
data_uri_characters | integer | characters | Length of data:<mime_type>;base64,<encoded> (no line breaks). |
data_uri_prefix | string | The prefix that precedes the Base64 payload. | |
decoded_from_encoded | string | How to recover the byte count from an encoded length: 3 × encoded / 4 − padding. |
Example
3 bytes: {"size_bytes":3,"line_length":0} → {"encoded_characters":4,"padding_characters":0,"overhead_percent":33.33,"encoded_with_line_breaks":4,"data_uri_characters":26}
1,000,000 bytes with MIME line breaks: {"size_bytes":1000000,"line_length":76} → {"encoded_characters":1333336,"padding_characters":2,"overhead_percent":33.33,"line_count":17544,"encoded_with_line_breaks":1368424,"decoded_from_encoded":"3 × 1333336 / 4 − 2 padding = 1000000 bytes"}
GET https://tttkmbb.com/api/v1/calculate/base64-size?size_bytes=3&line_length=0
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/base64-size(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/base64-size · Markdown: https://tttkmbb.com/developer/base64-size.md · JSON definition: https://tttkmbb.com/developer/base64-size.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="base64-size" - OpenAPI operationId:
calculate_base64_size - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
FAQ
Why is Base64 33 % larger?
Every 6 bits of input become one 8-bit ASCII character, so 3 bytes turn into 4 characters (4/3 = 1.333); padding adds up to 2 more characters at the end.
How many bytes does a Base64 string of length L decode to?
3 × L / 4 minus the number of trailing = characters (L must be a multiple of 4 when padded).
Does gzip undo the overhead?
Partly: Base64 text compresses to roughly the size of the compressed original plus a few percent, but only if the transport compresses it (e.g. HTTP content-encoding).
Related calculators
- Data Storage Converter — Convert the resulting byte counts between KB, MiB and other units.
- Download Time Calculator — Transfer time of the encoded payload.
- Text Hash Calculator — Digest of the same data.