Back to Blog
📦

What Is Base64 Encoding?

If you've spent any time working with web APIs, email protocols, or data URIs, you've probably encountered a string like SGVsbG8gV29ybGQ=. That is Base64 Encoding.

But what is it, and why do we use it?

🌐 The Problem Base64 Solves

Computers communicate using binary (1s and 0s). However, many early protocols (like SMTP for email) were designed to only handle basic text characters (specifically, 7-bit ASCII).

If you try to send a raw image file or binary data over a text-only protocol, the system gets confused by the non-printable characters and corrupts the data.

Base64 fixes this. It takes raw binary data and translates it into 64 safe, printable characters:

  • A-Z (26 characters)
  • a-z (26 characters)
  • 0-9 (10 characters)
  • + and / (2 characters)

🧮 How It Works

Base64 works by taking groups of 3 bytes (24 bits) and splitting them into 4 groups of 6 bits. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet.

Because it takes 3 bytes of input and turns it into 4 bytes of output, Base64 increases the file size by about 33%.

The Padding Character =

Sometimes, your data doesn't divide perfectly into groups of 3 bytes. When this happens, Base64 uses the = character at the end as "padding" to make up the difference.

🚀 Common Use Cases

  1. Email Attachments: Sending images or PDFs via SMTP.
  2. Data URIs: Embedding a small image directly in HTML or CSS to save an HTTP request (<img src="data:image/png;base64,..." />).
  3. Web APIs: Sending binary files as part of a JSON payload.

Ready to encode or decode some text? Try the tool below!

Try it yourself!

Put this theory into practice using our free, client-side tool.

Open Tool