Upload a file
  1. base64hub
  2. Text tools
  3. Size calculator

Base64 Size Calculator

Enter a size in bytes, KB or MB, or drop a file, to get the exact Base64 length with and without padding, line breaks and data URI prefix. Reverse mode turns a Base64 length back into bytes.

Free no sign-up, no limits Local nothing uploaded Exact counts padding, line breaks, prefixes Updated Oct 27, 2026
Only the size is read; the file content is not opened.

Processed in your browser. This page cannot send your data anywhere – how we know

How to calculate Base64 size

  1. Keep Bytes → Base64 length selected and type the Original size, choosing the Unit. Under Units, pick 1 KB = 1000 B or 1 KiB = 1024 B to match how your size was measured.
  2. Or drop a file on the box. Only its size is read; the file’s content is never opened.
  3. Read the table: padded and unpadded length, the overhead in percent, a custom wrap (set Line length and Line break), MIME email lines, a PEM body, a data: URI with the file’s MIME type and a JSON string with quotes.
  4. For the other direction, switch to Base64 length → bytes, enter the length, say whether it includes line breaks, and choose the Padding case: known, unknown (0–2 ×) or none. Pasting the Base64 itself gives an exact answer.

The live formula under the table repeats the calculation with your own numbers, which is handy for a code comment or a ticket.

The formula and why it is 33%

Base64 turns every 3 bytes into 4 characters, each carrying 6 bits. The last group is padded with = to a full 4 characters, so:

padded   = 4 × ⌈n ÷ 3⌉
unpadded = ⌈4n ÷ 3⌉
decoded  = (characters × 3 ÷ 4) − number of "=" signs

For large inputs that is a fixed 33.3% increase. For tiny ones the padding dominates: one byte becomes four characters, an overhead of 300%. The table below was produced with the same code the calculator runs:

OriginalPadded Base64No paddingMIME (76 + CRLF)PEM (64 + LF)
1 byte4244
100 bytes136134138138
1,000 bytes (1 KB)1,3361,3341,3701,356
1,024 bytes (1 KiB)1,3681,3661,4021,389
1,048,576 bytes (1 MiB)1,398,1041,398,1021,434,8961,419,949
5,000,000 bytes (5 MB)6,666,6686,666,6676,842,1066,770,834

Line breaks are counted between lines, with none after the last line. Some encoders, Python’s base64.encodebytes for example, end every line including the last with \n, which adds one more break. Add the prefix for a data URI: data:image/png;base64, is 22 characters.

Planning around size limits

Typical limits worth checking before something fails:

  • Request body limits. If an endpoint accepts 10,000,000 bytes and the file goes in a JSON field, the file can be at most about 7,500,000 bytes, minus the rest of the JSON. Switch to reverse mode, enter the limit, and subtract your field names.
  • Database columns and environment variables. A VARCHAR(255) holds Base64 of at most 189 bytes; 190 bytes already need 256 characters.
  • Email. MIME attachments are wrapped at 76 characters with CRLF, so they grow by about 37% in total. A message size limit therefore admits files only about 73% of its size. Base64 in email has the details.
  • Data URIs in HTML or CSS. Every inlined image costs a third more than the file and cannot be cached separately. Data URI performance explains when it still pays off.

Base64 length in code

Every language can compute it without encoding anything:

import math

def b64_len(n, padded=True):
    return 4 * math.ceil(n / 3) if padded else math.ceil(4 * n / 3)

print(b64_len(1048576), b64_len(1048576, padded=False))

That prints 1398104 1398102. In JavaScript the padded length is 4 * Math.ceil(n / 3). To check a string you already have, len(s) * 3 // 4 - s.count("=") gives the decoded size, after you strip line breaks. If reverse mode reports an impossible length, such as a remainder of 1 after dividing by 4, the string is damaged: run it through the Base64 validator to find out where.

FAQ

What is the formula for Base64 length?

With padding it is 4 × ⌈n ÷ 3⌉ characters for n bytes. Without padding it is ⌈4n ÷ 3⌉. Line breaks, a data: prefix or JSON quotes come on top.

How big is a file after it is decoded from Base64?

Take the number of Base64 characters (without line breaks), multiply by 3, divide by 4, and subtract one byte for each = at the end. A 1,400,000-character string decodes to between 1,049,998 and 1,050,000 bytes depending on its padding.

What is the largest file I can send through an API with a 10 MB request limit?

Roughly 7.5 MB if the limit is 10,000,000 bytes, because 10,000,000 × 3 ÷ 4 = 7,500,000, minus whatever JSON fields and headers surround the string. Use reverse mode with the limit as the length to get the exact figure.

Does gzip undo the Base64 overhead?

On the wire, mostly. Gzip squeezes Base64 back to roughly the size of the bytes it encodes: 1,000,000 random bytes give 1,333,336 Base64 characters, which gzip to 1,009,976 bytes. Limits that count the text itself, such as a JSON field, a database column or an unencoded request, still see the full third.