CCalclabhub

Text & Writing

Output length from input length

Each group of three input bytes becomes four output characters, and the final partial group is padded, so the length is always a multiple of four.

Last updated

The Formula

Base64 characters = 4 x ceil(bytes / 3)

Each group of three input bytes becomes four output characters, and the final partial group is padded, so the length is always a multiple of four.

SymbolMeaning
nInput bytes
LOutput length

What Each Symbol Means

nbytes

Input bytes

The size of the data in bytes.

Lcharacters

Output length

How many Base64 characters the result contains.

See It Worked With Real Numbers

A formula on its own does not tell you which number goes where. The how to encode text to base64 page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.

Where This Formula Appears

This equation is the working core of How To Encode Text To Base64, filed under Everyday Life. Every number the guide produces comes from substituting into this one line.

Common Questions

What is the formula for Output length from input length?

The formula for Output length from input length is Base64 characters = 4 x ceil(bytes / 3). Each group of three input bytes becomes four output characters, and the final partial group is padded, so the length is always a multiple of four.

What units should I use with Output length from input length?

Substitute n in bytes, L in characters. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.

What is a common mistake when using Output length from input length?

Treating Base64 as encryption. Base64 has no key and is trivially reversible. Anything encoded with it is readable by anyone, so it must never be used to protect a secret.