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.

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.