Base64 Encoded Size Calculator

Base64 turns three bytes into four printable characters, so it costs exactly one third more than the binary it encodes — plus up to two padding characters, plus two bytes for every MIME line break if the output is wrapped. This calculator gives the exact encoded length for base64, base64url, base32 and hex, the padding added, the overhead in bytes and per cent, the length of an equivalent data URI, and the decoded size that an encoded length corresponds to. The formulas follow RFC 4648, and the line-wrapping option follows RFC 2045.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Raw data sizeSize of the binary before encoding. KB here is 1,000 bytes; pick KiB if you mean 1,024.100 bytes
Encodingbase64 and base64url produce identical lengths; only the alphabet differs.base64 — standard alphabet (RFC 4648 §4)
Include = padding charactersStandard base64 pads to a multiple of four characters. base64url in JSON Web Tokens and many APIs omits it; hex never uses it.Yes
Wrap at 76 characters (MIME)RFC 2045 email bodies wrap encoded output; each line is terminated by a two-byte CRLF, which this option counts.No
MIME type for the data URIUsed only to measure the data: URI prefix, which is 'data:' plus this string plus ';base64,'.image/png
Encoded length to decodeReverse direction: enter a character count you already have and see how many bytes it decodes to.10000 chars

It returns

  • Encoded size — Total transmitted size including padding and any line breaks, in kilobytes of 1,000 bytes.
  • Encoded size in bytes — Every character of these alphabets is one ASCII byte, so characters and bytes are the same count.
  • Bytes added by encoding
  • Overhead — Added bytes as a percentage of the original. Base64 tends to 33.333% for large inputs.
  • Padding characters added
  • Length of an equivalent base64 data URI — 'data:' + MIME type + ';base64,' + the padded base64 payload.
  • Bytes an encoded length decodes to

The formula

Lpad=4n3
Lraw=kng
Lmime=L+2L76

In plain text: base64 padded = 4 × ⌈n/3⌉; unpadded = ⌈4n/3⌉; overhead → 33.33%

  • nInput size before encoding (bytes)
  • LEncoded length; every character is one ASCII byte (chars)
  • gInput group size — 3 for base64, 5 for base32, 1 for hex (bytes)
  • kOutput group size — 4 for base64, 8 for base32, 2 for hex (chars)

The general form is L = k·⌈n/g⌉ with padding and ⌈k·n/g⌉ without it. Base64 takes 3 bytes (24 bits) and emits 4 six-bit symbols, so the asymptotic ratio is 4/3 exactly.

Updated Category Computer Science, Data & Application Metrics Verified against published test cases Reading time 12 min

Why base64 costs exactly one third

Base64 exists to move arbitrary bytes through channels that only accept text. Email bodies, URLs, JSON strings, XML attributes and HTML documents are all text, and a byte with value 0x00 or 0x1B has no business in any of them. The encoding maps binary onto 64 characters that survive every reasonable transport: A–Z, a–z, 0–9 and two symbols.

Sixty-four characters is 26, so each character carries exactly six bits. Three input bytes are 24 bits, which divides evenly into four six-bit symbols. That is the entire design: 3 bytes in, 4 characters out, and since each character is transmitted as one ASCII byte, the output is 4/3 of the input. One third more, or 33.33% overhead — a constant, not an estimate.

When the input is not a multiple of three, the final group is short and the encoder pads. One leftover byte is 8 bits, which fills two six-bit symbols with four bits to spare, so two = characters are appended. Two leftover bytes are 16 bits, filling three symbols, so one = is appended. The padding carries no data; it exists so a decoder reading a concatenated stream knows where the last group ended and how many bytes it held.

The other encodings in this calculator are the same idea at different ratios. Base32 uses 32 characters, so five bits each; five bytes (40 bits) become eight characters, a ratio of 8/5 and 60% overhead — the price of an alphabet that survives case-insensitive handling and being read aloud. Hex uses 16 characters, four bits each, so every byte becomes exactly two characters: 100% overhead, no padding, and no group arithmetic at all.

The exact formulas, including the ceiling functions

With padding: L = 4 × ⌈n/3⌉. Count the groups, rounding up, and multiply by four. This is always a multiple of four, which is what a strict decoder expects.

Without padding: L = ⌈4n/3⌉. Count only the characters that carry data. For n ≡ 1 (mod 3) this is two characters into the final group; for n ≡ 2 (mod 3) it is three.

The difference between the two is the padding count: 0 when n is a multiple of 3, 2 when the remainder is 1, and 1 when the remainder is 2. Note the inversion — one leftover byte produces two padding characters and two leftover bytes produce one — which is a common source of off-by-one errors when people write the arithmetic from memory.

MIME wrapping. RFC 2045 requires encoded bodies to be broken into lines of no more than 76 characters, each terminated by a CRLF. That is two extra bytes per line, so the wrapped size is L + 2⌈L/76⌉. On a large payload this adds a further 2.63% — 2 bytes per 76, so 2/76 = 0.0263 — bringing the total overhead from 33.33% to about 36.84%. Implementations differ on whether the final line carries a terminator; this calculator counts one, so a tool that omits it produces output two bytes shorter.

Data URIs. A data URI is data: + the MIME type + ;base64, + the payload. The fixed part is 5 + 8 = 13 characters plus the length of the MIME type, so data:image/png;base64, is 22 characters. That prefix is negligible for an image and is not negligible for a 20-byte inline SVG fragment, where it can exceed the payload.

Decoding. Going the other way, n = 3L/4 for base64, with the exact figure reduced by one byte per padding character. The calculator's reverse output floors the division, which gives the maximum bytes an encoded length of that size can hold.

Worked example: inlining a 100 KB PNG as a data URI

You have a 100,000-byte PNG and you are deciding whether to inline it in a stylesheet as a data URI.

  1. Groups. ⌈100,000 ÷ 3⌉ = 33,334, because 3 × 33,333 = 99,999 leaves one byte over.
  2. Padded length. 33,334 × 4 = 133,336 characters.
  3. Unpadded length. ⌈400,000 ÷ 3⌉ = ⌈133,333.33⌉ = 133,334 characters.
  4. Padding. 133,336 − 133,334 = 2 characters, consistent with a remainder of one byte.
  5. Overhead. 133,336 − 100,000 = 33,336 bytes, which is 33,336 ÷ 100,000 = 33.336%. Slightly above the asymptotic 33.333% because of the padding.
  6. Data URI. data:image/png;base64, is 22 characters, so the whole URI is 22 + 133,336 = 133,358 characters.
  7. If it were an email attachment. Wrapping at 76 characters gives ⌈133,336 ÷ 76⌉ = 1,755 lines and 3,510 bytes of CRLF, for a total of 136,846 bytes — an overhead of 36.846%.

Compare the alternatives on the same 100,000 bytes. Hex would produce 200,000 characters. Base32 would produce 8 × ⌈100,000 ÷ 5⌉ = 8 × 20,000 = 160,000 characters exactly, with no padding because 100,000 divides by five. A separate binary file would transfer 100,000 bytes plus one HTTP request. The inline version saves the request and costs 33,358 extra bytes every time the stylesheet is fetched and cannot be cached separately from it.

What to do with the overhead figure

Judge the 33% against what it buys. For a small icon inlined in CSS, saving a round trip is usually worth a third more bytes, especially on a high-latency connection where the request costs more time than the payload. For anything large, the calculation reverses: a 2 MB image inlined into a document adds 667 KB, is re-downloaded whenever the document changes, and cannot be cached, served from a CDN or lazily loaded on its own.

Check whether compression recovers the overhead. Base64 output is highly structured text, and HTTP transports normally apply gzip or Brotli. On base64-encoded data that is already compressed — a PNG, a JPEG, a ZIP — the compressor finds little to remove, and you keep most of the third. On base64-encoded text or uncompressed data, the compressor typically recovers a large part of it. The rule of thumb worth carrying is that base64 plus gzip is close to raw plus gzip for compressible content and close to raw plus a third for incompressible content.

Watch the multiplication factor in JSON APIs. A response containing many base64 fields pays the overhead on each, and if the payload is then stored in a database as text and indexed, the cost repeats in storage and in memory. Where an API returns binary regularly, a separate endpoint that serves the bytes directly is usually the right design, with the base64 field reserved for small values such as cryptographic digests.

Do not use base64 as a security measure. It is an encoding, not encryption: anyone can decode it in one line, and it is fully reversible by design. If the payload needs protecting, encrypt it and then encode the ciphertext — in that order — and size the key with the key brute-force time calculator.

Finally, if the encoded blob crosses a network you are budgeting for, feed the encoded figure rather than the raw one into the data transfer time calculator, and remember that packet headers add their own overhead on top — quantified by the MTU and MSS overhead calculator.

Encoded length for small inputs, and overhead by encoding

Exact base64 lengths for the first few input sizes, showing where padding appears. Padded length is 4⌈n/3⌉; unpadded is ⌈4n/3⌉.
Input bytesPadded charsUnpadded charsPaddingOverhead (padded)
1422300%
2431100%
344033.3%
4862100%
587160%
688033.3%
101614260%
100136134236%
1,0001,3361,334233.6%
100,000133,336133,334233.336%

The overhead only approaches 33.33% once the input is large enough for the padding to be lost in the rounding. On very short values — a 16-byte key, a 4-byte counter — the padded overhead is materially higher, which is one reason token formats such as JWT drop the padding.

Overhead by encoding family

Ratios are the output group divided by the input group. The last column applies each to 100,000 bytes.
EncodingInput groupOutput groupChars per byteOverhead100,000 bytes becomes
Ascii85 / base854 bytes5 chars1.2525%125,000 chars
base64 and base64url3 bytes4 chars1.33333.3%133,336 chars
base325 bytes8 chars1.660%160,000 chars
base16 (hex)1 byte2 chars2100%200,000 chars
quoted-printable, binary data1 byteup to 3 charsup to 3up to 200%up to 300,000 chars

Quoted-printable encodes each byte outside the printable ASCII range as an = followed by two hex digits, so it is efficient for mostly-text content and worse than hex for arbitrary binary. That is exactly why MIME defines both and lets the sender choose.

Mistakes and gotchas

  • Reversing the padding rule. One leftover byte produces two = characters; two leftover bytes produce one. The relationship is inverted from what most people remember.
  • Assuming base64url is shorter. It uses - and _ in place of + and / so the value survives URLs and filenames. The length is identical; only percent-encoding is avoided.
  • Forgetting that URLs percent-encode standard base64. Put standard base64 in a query string and + and / become %2B and %2F, three characters each. That can add far more than the 33%, which is precisely why base64url exists.
  • Ignoring line breaks in email. MIME wrapping adds 2.63% on top of the encoding, and some libraries wrap by default while others do not.
  • Treating base64 as compression or as security. It is neither. It always makes data larger, and it is trivially reversible.
  • Double-encoding. Base64 applied twice costs 1.333² = 1.778, or 78% overhead. It happens more often than it should when a value passes through two layers that each encode defensively.
  • Storing base64 in a fixed-width column sized for the raw data. A 16-byte value needs 24 characters padded or 22 unpadded, not 16.
  • Counting characters rather than bytes for a non-ASCII MIME type. Data URI prefixes are ASCII in practice, but if you build one programmatically from a UTF-8 string, measure bytes.

Key terms

Encoding quantum
The smallest group the encoder processes as a unit — 24 bits for base64, 40 bits for base32, 8 bits for hex. Padding exists to complete a partial quantum.
Padding character
The = appended to fill a partial quantum. It carries no data and tells a decoder how many bytes the final group held.
base64url
The RFC 4648 §5 variant that replaces + and / with - and _ so the value can appear in a URL path, query string or filename without percent-encoding. Same length as standard base64.
Data URI
A URI that carries its content inline, of the form data:[mediatype][;base64],data. Saves a request at the cost of the encoding overhead and of any caching independence.
Quoted-printable
The other MIME content-transfer-encoding, which leaves printable ASCII untouched and expands everything else to three characters. Efficient for text, poor for binary.

When to encode at all

Base64 is a workaround for channels that cannot carry bytes, and modern protocols increasingly can. HTTP has always carried binary bodies; the reason base64 persists on the web is that binary cannot appear inside a JSON string, an XML attribute or a CSS declaration. Where you control both ends, a multipart request or a separate binary endpoint avoids the encoding entirely and is usually the better design.

Where the encoding is unavoidable, choose the variant that matches the channel. Use base64url in URLs, path segments and JSON Web Tokens. Use standard base64 in MIME and in most APIs. Use base32 when a human has to transcribe or read the value aloud, because its alphabet avoids case sensitivity and confusable characters — this is why TOTP secrets and onion addresses use it despite the 60% cost. Use hex for short values such as digests and MAC addresses, where the doubling does not matter and the byte-per-two-characters mapping makes the value easy to read.

Two neighbouring calculations matter when you are budgeting a payload. If the underlying data is an image, the image file size calculator gives you the pre-encoding size from pixel dimensions and bit depth. And if you are comparing a compression scheme against the encoding cost, the data compression ratio calculator converts between ratios and percentage space saved so you can see whether compressing before encoding wins back more than the third you are about to add.

Frequently asked questions

How much bigger is base64 than the original data?

Exactly 33.33% for large inputs, because three bytes become four characters and each character is one byte. Short inputs are worse: one byte becomes four characters (300% overhead) and two bytes become four (100%), because padding fills the partial group. Add a further 2.63% if the output is wrapped at 76 characters for MIME, bringing the total to about 36.85%.

Why does base64 sometimes end with one = and sometimes two?

It depends on the remainder when the input length is divided by three. A remainder of one — a single leftover byte — fills two of the four six-bit symbols, so two = characters complete the group. A remainder of two fills three symbols, so one = is appended. When the length is an exact multiple of three there is no padding at all. The relationship is inverted from the intuition that more leftover bytes mean more padding.

Can I drop the padding?

Often, but check the consumer first. JSON Web Tokens require base64url without padding, and many APIs accept unpadded input. A strict RFC 4648 decoder may reject it, and padding is genuinely needed when encoded values are concatenated without a delimiter, because it is the only marker of where each value's final group ends. Dropping it saves at most two characters, so do it for compatibility reasons rather than for size.

Is base64url smaller than base64?

No — the two produce the same number of characters, because they differ only in which two symbols complete the 64-character alphabet. base64url uses - and _ instead of + and /. The saving appears when the value goes into a URL: standard base64's + and / must be percent-encoded to %2B and %2F, three characters each, which can inflate the value far beyond the nominal 33%. base64url avoids that entirely.

Should I inline images as data URIs?

For small assets, often yes; for large ones, rarely. Inlining saves an HTTP round trip, which matters most on high-latency connections and for images needed during first paint. It costs a third more bytes, prevents the asset being cached separately from the document that contains it, and means the whole document is re-downloaded whenever the image changes. A few kilobytes is a reasonable ceiling; 100 KB adds 33 KB to every fetch of the containing file.

Does gzip undo the base64 overhead?

Partly, and it depends on the payload. Base64 output is structured text and compresses well when the underlying data is compressible, so base64-encoded text plus gzip ends up close to raw text plus gzip. When the underlying data is already compressed — PNG, JPEG, ZIP — there is little redundancy for the compressor to exploit and you keep most of the third. Measure it on your own data rather than assuming either outcome.

How do I work out the original size from a base64 string?

Multiply the character count by 3 and divide by 4, then subtract one byte for each = at the end. A 133,336-character string with two padding characters decodes to 133,336 × 3 ÷ 4 − 2 = 100,000 bytes. If the string is unpadded, take the floor of 3L/4. Strip any whitespace or line breaks before counting, since MIME-wrapped output contains CRLF pairs that are not part of the encoding.

Why does base32 cost 60% when base64 costs 33%?

Because each base32 character carries five bits rather than six, so eight characters are needed for every five bytes: 8/5 = 1.6. You pay that extra for an alphabet that is case-insensitive and avoids visually confusable characters, which matters when a human has to read or type the value. TOTP shared secrets and Tor onion addresses use base32 for exactly this reason.

Is base64 a form of encryption?

No. It is a reversible encoding with no key and no secret, decodable by anyone in a single command. It provides no confidentiality whatsoever. If the data needs protecting, encrypt it first and base64-encode the ciphertext afterwards, so the encoding is doing the job it is designed for — carrying arbitrary bytes through a text channel.

References