Base64 is a notation that rewrites arbitrary bytes using 64 safe characters. It is often mistaken for a kind of encryption, but it hides nothing. Knowing how it works, how much it grows and which variants exist saves a lot of confusion.
Encoding is not encryption
Base64 is a publicly specified notation with no key. Anyone can reverse it using the same rules, so wrapping a password or personal data in Base64 does not hide it in any meaningful way.
Encryption makes data unreadable without a secret key, while encoding only changes the shape of data so another system can carry it. The goals are different. If you need protection, use real encryption or hashing, and use Base64 only to write the result as text.
SGVsbG8= is Hello written in Base64, and any decoder turns it back into the original instantly.
When you see a Base64-looking value in a log or config file, decode it once. Assume it is not a secret just because it looks scrambled.
A key or token hidden with Base64 inside source code is exposed the moment the code is shared.
How it works and how much it grows
Take the input three bytes at a time, which is 24 bits. Split those 24 bits into four groups of 6 bits, and map each group to one character of a 64-character alphabet (A-Z, a-z, 0-9, +, /). Three bytes become four characters, so the output is about one third larger than the input.
If the input length is not a multiple of three, one or two = characters are appended as padding so the output length is a multiple of four. A final group of one byte gets ==, and a group of two bytes gets =.
M becomes TQ==, Ma becomes TWE=, and Man becomes TWFu, which shows the padding rule clearly.
Some formats insert line breaks at fixed intervals, so the same data can look different as a string only because of whitespace.
Text such as Korean is first turned into bytes (usually UTF-8) and then encoded, so both sides must agree on the character encoding or the text will come out garbled.
The URL-safe variant
In the standard alphabet, + and / have special meanings in addresses and file paths. A URL-safe variant replaces them with - and _, and it frequently drops the trailing = padding as well.
The parts of a login token (JWT) are the best-known example. Feeding a URL-safe string to a standard decoder can raise an error or give a wrong result, so check which flavor you have before decoding.
If you see - or _, it is probably URL-safe; if you see + or /, it is probably the standard form.
A string with missing padding can be decoded by a standard decoder once you add = characters until the length is a multiple of four.
When you place a value inside a query string, also think about whether it needs percent-encoding on top of Base64.
When to use it and when not to
Use Base64 when you must move binary data through a channel that only handles text safely. Email attachments, small images embedded directly in a page as data URLs, and certificates or key files stored in text-based settings are typical cases.
For large files it is a poor choice because the size grows by a third and processing is slower; send the file as it is whenever you can. Remember that it offers no compression and no security.
A small icon written as data:image/png;base64,... saves one request, but it cannot be cached separately from the page.
The HTTP basic authentication header is just user:password in Base64, so it must only travel over an encrypted connection.
Try the Base64 tool on this site: type some text, encode it, decode it again, and the principle becomes obvious in a minute.
When decoding fails: what to check
Most decoding errors come from a truncated string, the wrong variant, or stray whitespace. Checking whether the length is a multiple of four and whether any illegal characters appear usually narrows the cause quickly.
Copying often drags along line breaks, leading or trailing spaces, or quotation marks. If the result looks like random symbols rather than text, the original may be binary data such as an image or a compressed file, not text at all.
A length that leaves a remainder of one when divided by four means something was cut off, so fetch the original again.
For a URL-safe string, replace - with + and _ with / before using a standard decoder.
If the result is garbled Korean, consider that the original text may not have been encoded as UTF-8.