Where Base64 Shows Up and What It Does
Open the raw source of an email and scroll past the headers. Sooner or later you hit a block of text that looks like someone fell asleep on the keyboard: long lines of mixed upper and lower case letters, a few digits, the odd plus sign and slash, ending in one or two equals signs. It is not a password and nothing is broken. It is a file attachment, written out as text. That writing system is Base64, and you have been bumping into it for years without knowing its name.
The same alphabet soup turns up in places you would never look. Your browser sends it every time you log in to a site that uses basic auth. The token that keeps you signed in to an app is built from it. A tiny image on a web page can be stored as one long Base64 string right inside the HTML. Once you learn to spot it, you start seeing it everywhere. Try it yourself with our Base64 Encoder / Decoder. It takes ten seconds to turn a sentence into Base64 and back.
Quick answer: Base64 turns binary data into text using 64 characters: A-Z, a-z, 0-9, + and /. Every 3 bytes become 4 characters, so the output runs a third longer than the input. It is a transport format, not encryption, so anyone can decode it. It exists so binary data can travel through systems that handle text, like email, URLs and JSON.
What Base64 actually does
Some systems only speak text. Email was built for text, so a photo attached to a message has to be rewritten as text before it can be sent. A web address can only hold a small set of characters. A JSON file cannot hold raw binary at all. Base64 is the bridge between those two worlds. It takes any bytes, a photo or a login name, and writes them out using 64 characters that survive a trip through a text-only system.
The math behind it is simple. A byte holds 8 bits. Base64 splits the input into groups of 6 bits, and each group of 6 bits maps to one of 64 characters. Three bytes hold 24 bits, which split neatly into four groups of 6, so every 3 bytes become 4 characters. That is the whole trick, and it is also why the output is always about a third longer than the input.
When the input length is not a multiple of 3, the end of the string gets padding. One equals sign means the last group held 2 bytes, two means it held 1 byte. The padding looks odd, but it tells the decoder exactly where the data stops. The text Hello world becomes SGVsbG8gd29ybGQ=, with one equals sign at the end. The Arabic word السلام becomes 2KfZhNiz2YTYp9mF, with no padding at all, because its 9 bytes divide evenly into groups of 3.
You can try both in the tool. Type a sentence, watch the output grow by about a third, then flip to decode mode and paste the result back. It comes back exactly as you typed it, Arabic letters and emoji included.
It is not encryption
This is the part people get wrong, and it matters. Base64 hides nothing. There is no key, no password, no step that stops someone from reading what is inside. Anyone who sees a Base64 string can decode it in seconds, with a free tool or a single line of code. Paste SGVsbG8gd29ybGQ= into a decoder and it hands you Hello world straight back.
That trips people up because encoded text looks secret. It looks like the kind of string a password manager would generate. It is not. Encoding a password in Base64 and storing it that way is barely better than storing it in plain text. Real protection means hashing a password, or encrypting data with a key, and neither of those is what Base64 does. If you want a password that is actually hard to guess, our Password Generator makes one in a click, and our guide to creating a strong password explains how to keep it safe.
The classic example is HTTP Basic Auth. When a site asks your browser for a username and password this way, the browser sends them joined by a colon and encoded in Base64, like dXNlcjpwYXNz for user:pass. Anyone watching the traffic can decode that header in a second. That is why basic auth is only safe over HTTPS, where the whole connection is encrypted first. Base64 did the carrying. The encryption came from somewhere else.
Where you meet it every day
Base64 is one of those things that is invisible until you know its shape, and then you see it everywhere. Here are the places it turns up most.
- Email attachments. Every file you attach to an email is Base64-encoded before it is sent, because email was built to carry text. Open the raw source of a message with a photo attached and you will see pages of it.
- Data URLs. A small image or font can be embedded straight into a web page as
data:image/png;base64,...followed by the encoded bytes. It saves a separate download, at the cost of a bigger page. - Login headers. Basic auth sends username:password as one Base64 string. You have seen this header in browser tools even if you never read it.
- Tokens. The sign-in tokens used by many apps, including JWTs, are built from Base64URL segments separated by dots. The middle segment holds readable claims, which is one more reason never to put a secret in a token.
- Config files and APIs. When an API needs to accept a file inside a JSON request, the file usually arrives as a Base64 string, because JSON has no way to carry raw bytes.
If you want to see one in the wild, view the source of any email with an attachment. The encoded file is right there, lines and lines of it, sitting between the headers and the end of the message.
Base64 vs Base64URL
Standard Base64 has two characters that cause trouble in a web address: the plus sign and the slash. Both mean something in a URL, so a Base64 string pasted into a link can break it or change what the server reads. The equals signs at the end can cause trouble too.
Base64URL is a small fix for that problem. It swaps + for a hyphen and / for an underscore, and it usually drops the padding. The data inside is identical, only the wrapping changes. JWTs use this variant, which is why a token looks like three chunks of text joined by dots, with no equals signs anywhere.
Use the standard form for email and files, and the URL-safe form for anything that lives in a link or a token. Mixing them up is the most common reason a decode fails. If a decoder complains about your string, check which variant you have before you blame the data.
Four mistakes that waste your time
First, treating it as a lock. I covered this above, but it is worth saying twice: encoding is not encrypting. If a value has to stay secret, Base64 will not keep it that way.
Second, decoding with the wrong variant. A URL-safe string holds hyphens and underscores, and a standard decoder will reject them. Switch to the Base64URL mode and the same string decodes fine.
Third, forgetting the padding. Some tools drop the = signs, and some decoders refuse to work without them. Ours adds missing padding back for you, but if you paste a string into another tool and it complains, try adding one or two equals signs at the end.
Fourth, using btoa() on non-English text. JavaScript has a built-in pair of functions, btoa() and atob(), but they only handle Latin-1 characters. Hand them Arabic text or an emoji and they throw an error. The fix is to turn the text into UTF-8 bytes first, which is what our tool does, so السلام and a party emoji survive the round trip.
Frequently asked questions
Is Base64 the same as encryption?
No. Encoding changes how data looks, encryption changes who can read it. Base64 has no key and anyone can reverse it. If a value must stay secret, encrypt it or hash it instead. For a closer look at a different kind of encoding, see our guide to when URLs need encoding.
Why is Base64 output longer than the input?
Each character carries 6 bits instead of 8, so 3 bytes become 4 characters. The output runs about 33 percent longer than the input. For large files that extra size is a real cost, which is why big files are usually sent as files, not as Base64 text.
Can I decode a Base64 string by hand?
You can, with a table of the 64 characters, but it is slow and dull work. Paste it into a decoder instead. If you only need to check what a short string says, a tool answers in a second.
What does the = at the end mean?
It is padding. It marks a short final group so the decoder rebuilds the exact original bytes. One = means the last group held 2 bytes, two == means it held 1 byte. Some variants drop it, and a good decoder adds it back.
Is Base64 safe for passwords?
No, and this is the mistake to avoid. Encoding a password does not protect it. Store passwords hashed, never encoded, and use our Password Generator to make a strong one in the first place.
Related guides
- When URLs Need Encoding (and When They Don't)
- How to Create a Strong Password and Keep It Safe
- On-Page SEO Checklist for Beginners
Next time a wall of mixed letters and equals signs shows up in a config file or an email header, do not scroll past it. Paste it into our Base64 Encoder / Decoder, flip to decode mode, and read what it says. It takes ten seconds, and once you have read a few of them, you will spot Base64 on sight.