How to calculate base64
Base64 is a way of writing any data — text, a picture, a file — using only 64 safe characters: the letters A to Z, a to z, the digits 0 to 9, plus and slash. You meet it whenever a file travels through a channel that only accepts plain text, such as an email attachment or a web page address. Try each example as you read on the Base64 Encoder Decoder, which encodes and decodes in your browser without sending anything anywhere.
Step 1: turn the text into bytes
Everything starts as bytes. Each letter you type is stored as a number: H is 72, e is 101, l is 108, l is 108 again, and o is 111. The word Hello is five letters, so it is five bytes. Non-English text works the same way, except that one character can take more than one byte: the rupee sign takes three bytes in UTF-8, and an emoji takes four. Count bytes, not characters, because Base64 works on bytes.
Step 2: take the bytes three at a time
Base64 works in groups of three bytes. Three bytes are 24 bits, and 24 splits neatly into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and each of those numbers is one character from the 64-letter alphabet. If the text does not divide neatly into threes, the last group is padded, which is covered in step 4. The word Hello has five bytes, so it splits into one full group of three bytes and one leftover group of two bytes.
Step 3: read each 6-bit group as a letter
The alphabet is fixed and worth learning in outline: A to Z are values 0 to 25, a to z are 26 to 51, 0 to 9 are 52 to 61, plus is 62, and slash is 63. Work through the three letters M, a, n to see it in action: their byte values are 77, 97 and 110, the 24 bits split into the groups 19, 22, 5 and 46, and those give the letters T, W, F and u. So Man encodes to TWFu.
Step 4: pad the end with equals signs
Base64 output is always a multiple of four characters long. If the last group had only one byte, two equals signs are added: M on its own encodes to TQ==. If it had two bytes, one equals sign is added: Ma encodes to TWE=. Three bytes need no padding at all, which is why Man is just TWFu. The padding is not decoration; it tells the decoder how many bytes the last group really held, so it can put the original text back exactly. Never drop the equals signs when you copy an encoded string, because without them the decoder cannot tell where the real data ends.
Hello → SGVsbG8= Man → TWFu Ma → TWE= M → TQ==
Worked example: Hello, World!
Take the 13 letters of Hello, World! and count the bytes: 13. Thirteen bytes make four full groups of three, with one byte left over, so the output is five groups of four characters, or 20 characters in total. The answer is SGVsbG8sIFdvcmxkIQ==, and the two equals signs at the end show that the last group held a single byte.
How much bigger does the text get?
Three bytes become four characters, so Base64 output is about a third bigger than the input: 4 divided by 3 is 1.33. On short text the padding makes the growth look worse — Hello grows from 5 bytes to 8 characters, which is 60% bigger — but on longer text the padding is a tiny fraction of the total and the growth settles at 33%. A 100-byte message becomes 136 characters, a 1,000-byte message becomes 1,336, and a 10-kilobyte file becomes 13,656 characters.
Frequently asked questions
How do I calculate Base64 by hand?
Turn the text into bytes, take them three at a time, split each group of 24 bits into four 6-bit numbers, and read each number off the 64-letter alphabet. Pad the end with = so the length is a multiple of four.
What is Hello in Base64?
SGVsbG8=. Hello is 5 bytes, which makes two groups and 8 characters, with one = at the end.
Why does Base64 make text bigger?
Three bytes become four characters, so the output is about a third bigger: 100 bytes become 136 characters and 1,000 bytes become 1,336.
What do the = signs at the end mean?
Padding. Two = signs mean the last group held one byte, one = means it held two bytes, and no = means the bytes divided exactly into threes.
More guides on the Base64 Encoder Decoder
- Base64 formula explained simply
- Base64: worked example step by step
- Base64 for beginners
- Common mistakes when calculating base64
- Base64 vs URL encoding: what's the difference
- How to use a base64 calculator
- Base64 quick reference table
- Base64 in real life: everyday examples
- Base64 practice questions with answers
Try the Base64 Encoder Decoder — free, in your browser.