What Is Base64 and Why Does It Exist?

A plain-language guide to Base64: what it does, why email, JSON and URLs need it, how it works with a tiny example, and why it is never a way to protect data.

Development 6 min read

If you have ever seen a long string of letters and numbers ending in one or two equals signs, such as "SGVsbG8gd29ybGQ=", you have met Base64. It shows up in emails, web pages, API tokens and configuration files, and it often looks mysterious.

In this guide you will learn what Base64 is, why it was invented, how it works step by step, where you will find it and the one thing everyone should remember: Base64 is not encryption.

Encode text or files to Base64 Convert text and files to Base64 right in your browser. Nothing is uploaded or stored. Open the Base64 encoder

What is Base64?

Base64 is a way of writing any data, including images, files and text, using only 64 safe characters: the uppercase letters A-Z, the lowercase letters a-z, the digits 0-9 and the symbols + and /. A special character, =, is sometimes added at the end as padding.

It is an encoding, not a compression or a lock. It simply changes how the same information is represented, and it can always be converted back to the original.

Why does Base64 exist?

Computers store everything as bytes, and a byte can hold any value from 0 to 255. But many systems were designed to carry plain text only. Raw bytes can contain control characters, line breaks or values that these systems change, cut or reject, which corrupts the data on the way.

Base64 solves this by using only characters that survive almost any text channel. Typical cases:

  • Email (MIME): attachments such as photos and PDFs are Base64 encoded inside the message.
  • JSON and XML: they have no native way to hold binary data, so files are sent as Base64 strings.
  • URLs and HTML/CSS: small images can be embedded directly in a page as a data URI.
  • Configuration files and HTTP headers: places where only printable text is allowed.

How Base64 works in simple terms

Base64 reads the data in groups of 3 bytes, which is 24 bits. It splits those 24 bits into 4 groups of 6 bits. Each 6-bit group is a number from 0 to 63, and that number is looked up in the Base64 alphabet to pick one character.

So every 3 bytes become 4 characters. If the data does not divide evenly by 3, one or two = signs are added at the end as padding. Because 4 characters replace 3 bytes, the result is about 33% larger than the original.

A tiny worked example

Take the word "Man". In bytes, M = 77, a = 97 and n = 110, which is 01001101 01100001 01101110 in binary. Regrouped in sets of 6 bits, that gives 010011, 010110, 000101 and 101110, which are the numbers 19, 22, 5 and 46.

In the Base64 alphabet these numbers map to T, W, F and u. So "Man" becomes "TWFu". Try it yourself in the encoder and you will get exactly the same result.

Tip: "Ma" becomes "TWE=" and "M" becomes "TQ==". The equals signs show how many bytes were missing from the last group.

Where you see Base64 every day

  • Data URIs: images embedded in HTML or CSS, such as "data:image/png;base64,iVBOR...".
  • JWT tokens: the header and payload of a JSON Web Token are Base64URL strings separated by dots.
  • Basic authentication: the HTTP header "Authorization: Basic ..." carries "user:password" encoded in Base64.
  • Email attachments: every attached file travels as Base64 text inside the message.
  • APIs and certificates: file contents in JSON, and PEM keys and certificates between "BEGIN" and "END" lines.

Base64URL: the web-safe variant

The characters + and / have special meaning in URLs and file names, and = can be a problem in query strings. Base64URL fixes this by replacing + with - and / with _, and it often omits the = padding.

It is used in JWT tokens, URL parameters and file names. If a Base64 string contains - or _ and will not decode, it is probably Base64URL, so switch the characters back or choose the matching option.

Base64 is not encryption

This is the most important point. Base64 has no key and no secret: anyone can decode it in a second, with a free tool or a single line of code. It only makes data look unreadable at a glance.

Never use Base64 to hide passwords, tokens, personal data or anything private. If data must be protected, use real encryption and secure transport such as HTTPS.

Warning: "SGVsbG8=" is not hidden, it is just "Hello" in another form. If you see a password in Base64, treat it as a plain-text password.

How to encode and decode Base64 in 3 steps

  1. Open the Base64 encoder to convert, or the Base64 decoder to read a Base64 string. Both work entirely in your browser.
  2. Paste your text (or pick a file), then run the conversion. For decoding, paste the Base64 string exactly as you received it.
  3. Copy the result. If decoding fails, check for missing padding, extra spaces or the Base64URL characters - and _.

Common mistakes to avoid

  • Using Base64 to protect data. It is encoding, not security.
  • Padding errors: removing or cutting off the = signs can make a string impossible to decode in strict tools.
  • Stray line breaks or spaces copied along with the string. Some tools wrap lines every 76 characters, so remove them if decoding fails.
  • Mixing text and bytes: text must be turned into bytes with an encoding such as UTF-8 first. If accents or emoji look broken after decoding, the encodings did not match.
  • Mixing standard Base64 and Base64URL, which use different characters for 62 and 63.
  • Forgetting the size: Base64 adds about 33%, so it is not a good way to store or send very large files.

Conclusion

Base64 exists to move binary data through channels that only understand text. It turns every 3 bytes into 4 safe characters, which makes the data about 33% bigger but able to travel through email, JSON, URLs and web pages. Use it for compatibility, never for secrecy, and use the free encoder and decoder whenever you need to convert something quickly.

Frequently asked questions

Is Base64 encryption?

No. Base64 is an encoding with no key or secret, so anyone can decode it instantly. Never use it to protect passwords or sensitive information.

Why does Base64 end with = signs?

The = is padding. Base64 works in groups of 3 bytes, and when the last group is incomplete one or two = signs fill it up so the length is a multiple of 4.

Why is Base64 about 33% bigger than the original?

Because every 3 bytes of data are written as 4 characters. That is 4 divided by 3, an increase of roughly one third, plus a little extra for padding.

What is the difference between Base64 and Base64URL?

Base64URL replaces + with - and / with _, and usually drops the = padding, so the result can be used safely in URLs and file names. JWT tokens use it.

Is it safe to use an online Base64 tool?

It is safe when the tool runs in your browser and does not send your data to a server. Our encoder and decoder work locally on your device and store nothing.

Free tools mentioned in this article

Keep reading

All articles