Vaultools
Menu

Base64

Base64 is an encoding that represents any sequence of bytes using 64 printable text characters, so binary data can travel through systems built for text such as email, JSON, URLs and HTTP headers. It is not encryption, and it makes data about a third larger.

How it works

Base64 reads the input three bytes (24 bits) at a time and splits those 24 bits into four groups of six. Each six-bit value, 0 to 63, is looked up in a 64-character alphabet:

ValuesCharacters
0–25A–Z
26–51a–z
52–610–9
62 and 63+ and /

The text Man is the bytes 01001101 01100001 01101110. Regrouped as 010011 010110 000101 101110, they are the values 19, 22, 5 and 46, which spell TWFu.

Padding and size

When the input length is not a multiple of three, the last group is short and = characters fill it out to four characters. One leftover byte gives == and two give =, so M becomes TQ== and Ma becomes TWE=.

Every three bytes become four characters, so the output length is 4 × ⌈n / 3⌉. Encoding 1,000 bytes gives 1,336 characters, an increase of about 33%.

Where it is used

Common pitfalls

References

Ads on this page

Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.

Go Pro to remove them →