MyWebUtils
Encoders / Decoders5 min read

What is Base64 Encoding? How to Encode and Decode Online

If you've ever dug into a JWT token, looked at an image embedded directly in a CSS file, or peeked at an HTTP Basic Auth header, you've seen those long, strange strings of characters ending in ==. That's Base64. It looks like nonsense, but it's actually one of the most practical tools in a developer's kit.

Most people assume Base64 is some kind of encryption. It isn't. It's an encoding scheme — a way to translate binary data (like an image or a file) into plain text. Once you understand why we need it and what it's doing, it stops being a mystery and starts being a tool you can use effectively.

What is Base64, really?

At its heart, Base64 is a way to represent binary data using only 64 safe, printable characters: A–Z, a–z, 0–9, +, and /. We also use the = sign for padding at the end.

The name comes from the fact that it uses a 6-bit encoding system. Since 2⁶ is 64, each Base64 character represents exactly 6 bits of data. Contrast that with standard ASCII text, where each character usually represents 8 bits (one byte).

The reason this exists is purely practical. A lot of older systems — like email servers or legacy network protocols — were built to handle only "printable text." If you try to send raw binary data through them, they might see a null byte or a control character and think the message is over, mangling your data in the process. Base64 bridges that gap by "hiding" the binary data inside a string of safe characters.

How the Encoding Works (The "3-to-4" Rule)

The logic is simple but clever. Base64 takes your binary data and splits it into groups of 3 bytes (24 bits). It then takes those 24 bits and reshuffles them into 4 groups of 6 bits each. Each of those 6-bit groups maps to one character in the Base64 alphabet.

Original Data:  "Man" (3 bytes)
Binary:         01001101  01100001  01101110
Reshuffled:     010011  010110  000101  101110 (4 groups of 6)
Decimal:        19      22      5       46
Base64 Alpha:   T       W       F       u
Result:         "TWFu"

The catch? Because you're using 4 characters to represent what used to be 3 bytes, the encoded version is always roughly 33% larger than the original. Keep that in mind if you're thinking about embedding a 5MB image directly into a JSON file — it's going to turn into a 6.7MB string.

Where You'll Actually Use This

1. JSON Web Tokens (JWT)

JWTs are the bread and butter of modern authentication. A token like header.payload.signature is actually three different Base64url-encoded JSON objects joined by dots. It's important to remember: because anyone can decode it, you should never put sensitive info like passwords in a JWT payload. It's meant for identification, not for hiding secrets.

2. Data URLs for Images

If you have a tiny icon or logo, you can avoid a separate network request by embedding it directly in your HTML or CSS using a Data URL:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUh..." />

This is great for performance if the image is only a few hundred bytes, but becomes a liability for larger files due to that 33% size overhead we mentioned earlier.

3. Email Attachments

The protocols that power email (SMTP) are very old and primarily text-based. When you attach a PDF or a photo, your email client Base64-encodes the entire file so it can travel safely through mail servers without being corrupted.

Base64 vs. Base64url

Standard Base64 uses + and /, which have special meanings in URLs. To avoid percent-encoding those characters, we use "Base64url." It's the same math, but it swaps + for - and / for _. It also makes the padding = signs optional. If you're building a URL-based system, this is the variant you want.

Wrapping Up

Base64 isn't about security; it's about compatibility. It's the universal language that lets binary data live inside text-based systems.

If you need to quickly check what's inside an encoded string or turn a piece of text into its Base64 equivalent, use our free Base64 Encoder / Decoder. It handles the UTF-8 complexities for you, so you don't have to worry about emojis or special characters breaking your code.

Try the free tool

Ready to use the Base64 Encoder / Decoder?

Open Base64 Encoder / Decoder