Tools
EN

What Is Base64 Encoding?

Base64 is a way to write any binary data using only 64 printable characters. Here is how it works, why it exists, and when you should (and should not) use it.

Base64 in one sentence

Base64 is a binary-to-text encoding defined in RFC 4648 that represents every 3 bytes of data as 4 characters from the alphabet A–Z, a–z, 0–9, + and /.

Why Base64 exists

Many systems were designed for text only: email (SMTP), JSON, XML, HTML attributes, URLs and terminals. Raw binary data such as images or PDFs can contain bytes that these systems would change or reject. Base64 converts the data into safe, printable characters so it survives the trip unchanged.

How Base64 encoding works, step by step

  1. Take the input bytes: M, a, n = 77, 97, 110.
  2. Write them as 24 bits: 01001101 01100001 01101110.
  3. Split the bits into four 6-bit groups: 010011 010110 000101 101110 = 19, 22, 5, 46.
  4. Look up each number in the alphabet: 19 = T, 22 = W, 5 = F, 46 = u.

So Man becomes TWFu. Decoding simply reverses these steps.

The Base64 alphabet

ValuesCharacters
0–25A–Z
26–51a–z
52–610–9
62+ (URL-safe: -)
63/ (URL-safe: _)
padding=

What the = padding means

When the input length is not a multiple of 3, the last group is filled up and marked with =: Ma becomes TWE= and M becomes TQ==. Padding never appears in the middle of a valid string.

Base64 variants

Base64 is not encryption

Base64 hides nothing: anyone can decode it instantly. It is often mistaken for protection because the output looks random. Use real encryption such as AES for secrets, and Base64 only to transport the encrypted bytes as text.

Size overhead

The encoded length is 4 × ⌈n / 3⌉ characters for n bytes, about 33% more than the original. With MIME line breaks it grows by a further 2–3%.

Where Base64 is used

Frequently asked questions

Is Base64 the same as encryption or hashing?

No. Encryption needs a key to reverse, hashing cannot be reversed at all, while Base64 can be decoded by anyone.

Why is it called Base64?

Because it uses an alphabet of 64 characters, so each character carries 6 bits of information (26 = 64).

How can I tell if a string is Base64?

It contains only A–Z, a–z, 0–9, +, / (or - and _), its length is usually a multiple of 4, and it may end with one or two = signs. The quickest test is to paste it into our decoder.

Updated: