Calcylator
Base64 Encoding

Base64 encoded size:
round up bytes ÷ 3, times 4

Work out exactly how many bytes a Base64 string takes, why the result always rounds up to a multiple of four, and what that costs in real payloads.

Calcylator Editorial Team

Updated · 5 min read

Base64 encoded size formula

The Base64 encoded size is ceil(bytes ÷ 3) × 4. A 1,000 byte input becomes ceil(333.33) × 4 = 334 × 4 = 1,336 bytes. The result is always a multiple of four.

Base64 reads input in groups of 3 bytes (24 bits) and writes each group as 4 characters, each carrying 6 bits. If the last group is short, the encoder pads the output with equals signs so the length still divides by 4.

Base64 encoded size =size = ceil(bytes ÷ 3) × 4
bytes:
size of the original data in bytes
ceil:
round up to the next whole number
size:
length of the Base64 text in bytes (one byte per character)
The Calcylator tool uses this exact formula and counts one byte per Base64 character, with no line breaks.
  • Original size

    250,000 bytes

  • Groups of 3

    ceil(250,000 ÷ 3) = 83,334

  • Multiply

    83,334 × 4

Encoded size

333,336 bytes

About 33.3% larger than the 250,000 byte original.

Why the size rounds up: padding

Because the formula rounds up, tiny inputs still produce a full block of four characters. One byte becomes 4 characters, two bytes become 4, and three bytes become 4. The fourth byte starts a new block, so 4 bytes become 8.

Small inputs
Original bytesEncoded sizePadding characters (=)
142
241
340
482
581
680

The padding count is 0 when the input length divides by 3, 1 when the remainder is 2, and 2 when the remainder is 1. That is why 3,000 bytes encode to exactly 4,000 but 1,000 bytes need 1,336.

Overhead at real file sizes

Original size and Base64 size
Original (bytes)Base64 (bytes)Extra bytes
10013636
1,0001,336336
100,000133,33633,336
1,000,0001,333,336333,336

For anything bigger than a few hundred bytes, the overhead settles at about 33%. A 1 MB image sent as a Base64 string in JSON becomes roughly 1.33 MB before any compression, and decimal units apply here: 1 MB is 1,000,000 bytes, while 1 MiB is 1,048,576 bytes.

A second example: a 2,048,000 byte file encodes to ceil(682,666.67) × 4 = 682,667 × 4 = 2,730,668 bytes. Check that it divides by 4 and is a little over one third larger.

Where Base64 size matters

  • Data URIs: embedding a small image in CSS or HTML adds about a third to its weight and cannot be cached separately.
  • JSON APIs that carry files as Base64 strings, where request size limits apply to the encoded size, not the original.
  • Email attachments, which use Base64 inside MIME and are therefore bigger on the wire than on your disk.
  • Storing encoded blobs in a database column, where the field must hold the larger length.

Take a small icon of 30,000 bytes. It divides exactly by 3, so the Base64 text is 30,000 ÷ 3 × 4 = 40,000 bytes, with no padding. Embedding it in a style sheet therefore adds 10,000 bytes to the page, and browsers must download it with the style sheet every time rather than caching the image on its own.

Common mistakes

  • Assuming exactly 33% extra. The true figure is 4 ÷ 3 plus padding, and small inputs grow by much more.
  • Forgetting to round up, which gives lengths that are not a multiple of four.
  • Ignoring line breaks. Some formats, such as MIME email, insert line breaks, which add a few more bytes that this formula leaves out.
  • Mixing 1,000-byte and 1,024-byte kilobytes when comparing against a limit. Decimal units use 1 KB = 1,000 bytes, while binary KiB uses 1,024.
  • Thinking Base64 is encryption or compression. It only changes the representation and makes data larger.
  • Measuring the encoded string in characters when a multi-byte text encoding is used. Base64 characters are plain ASCII, so one byte each.

Common questions

How do I calculate the size of Base64 encoded data?

Divide the original byte count by 3, round up to a whole number, then multiply by 4. For 1,000 bytes that is ceil(333.33) = 334, and 334 × 4 = 1,336 bytes. The result is always a multiple of four.

How much bigger is a Base64 string than the original?

About one third bigger for large data, because 3 bytes become 4 characters. A 100,000 byte file becomes 133,336 bytes. Very small inputs grow by a higher percentage because of padding, as 1 byte turns into 4.

Why is Base64 output always a multiple of 4?

Base64 turns each group of 3 bytes into 4 characters. If the last group has fewer than 3 bytes, the encoder adds equals signs as padding so the final length still divides evenly by 4. That keeps decoding simple.

How many bytes is 1 MB in Base64?

Using decimal units, 1,000,000 bytes becomes 1,333,336 bytes in Base64, about 1.33 MB. Binary units differ: 1 MiB is 1,048,576 bytes, which encodes to 1,398,104 bytes. Always check which unit your limit uses.

Does the Calcylator tool use KB as 1,000 or 1,024 bytes?

The Calcylator tool works in plain bytes, so no kilobyte conversion is needed for the formula. When comparing to limits, note that decimal units use 1 KB = 1,000 bytes and binary units such as KiB use 1,024.

Was this guide helpful?

Continue reading

View all blogs