How Base64 turns bytes into 64 characters
Base64, defined in RFC 4648, is a way to carry arbitrary bytes through channels that only handle plain text. It takes the input three bytes at a time, treats those 24 bits as four groups of 6 bits, and maps each group (a value from 0 to 63) to one character from the alphabet A to Z, a to z, 0 to 9, plus and slash.
Because every 3 bytes become 4 characters, encoded data is about one third larger than the original. When the input length is not a multiple of three, the last group is padded with one or two equals signs so the output length stays a multiple of four.
This encoder first converts your text to UTF-8 bytes and then applies Base64, which is what most APIs, email systems and programming languages expect. Characters outside plain ASCII take more than one byte in UTF-8, so they produce longer output than you might guess from the visible text.
Worked example: Man, Ma, M and café
The classic example is the word Man. The bytes are 77, 97 and 110, or 01001101 01100001 01101110 in binary. Regrouped into 6-bit chunks that is 010011 010110 000101 101110, which are the values 19, 22, 5 and 46. In the Base64 alphabet those are T, W, F and u, so Man encodes to TWFu.
Drop a letter and padding appears: Ma encodes to TWE= and M encodes to TQ==. The number of equals signs tells you how many bytes were missing from the final group of three.
Accented text shows the UTF-8 step at work. The word café is five bytes, not four, because é is stored as the two bytes C3 A9. Its Base64 form is Y2Fmw6k=. A tool that encoded é as a single Latin-1 byte would produce a different string, which is a common reason two encoders disagree.
Standard Base64 versus Base64URL
Plus, slash and equals all have special meaning in URLs, so RFC 4648 also defines a URL-safe variant. Base64URL swaps plus for a hyphen and slash for an underscore, and padding is usually dropped. The two bytes FB FF encode to +/8= in standard Base64 and to -_8 in Base64URL.
You will meet Base64URL in JSON Web Tokens, OAuth PKCE challenges and many signed URLs. Standard Base64 appears in data URIs, MIME email attachments, HTTP Basic authentication headers and PEM certificate files. This tool encodes with the standard alphabet. The decoder also accepts Base64URL input, missing padding and a data: URI prefix, converting them to standard Base64 before decoding.
Limits and common mistakes
The decoder shows the decoded bytes as text when they are valid UTF-8, which suits encoded strings, JSON and configuration values. Binary payloads such as a Base64 PNG or a ZIP file are not valid UTF-8, so instead of garbled text the tool reports the byte count and offers the result as a file download, with the extension guessed from the first bytes (PNG, JPEG, GIF, PDF, ZIP or WebP, otherwise .bin). To go the other way, the Encode a file option turns any file up to 10 MB into Base64.
Watch for invisible differences. A trailing newline in the input changes the output, and so does a space copied from a document. Base64 is also sometimes applied twice by accident: if a decoded result still looks like Base64, decode it again and check whether it now makes sense.
- Linux and macOS: echo -n 'text' | base64 avoids the trailing newline that plain echo adds.
- JavaScript: btoa only accepts Latin-1 characters, so encode text to UTF-8 bytes before calling it.
- Python: base64.b64encode('text'.encode('utf-8')) returns bytes; call .decode() to get a string.
Base64 Encoder / Decoder: frequently asked questions
Why does Base64 output sometimes end with = or ==?
Base64 works on groups of three bytes. If the input ends with one leftover byte the output gets two padding characters, and with two leftover bytes it gets one. The padding carries no data; it only keeps the encoded length a multiple of four.
How much larger does Base64 make a file?
The output is four characters for every three bytes, so roughly 33 percent larger. A 300 KB image becomes about 400 KB of Base64 text, and MIME email adds line breaks on top of that. This is why embedding large images as data URIs usually slows a page down.
Why does my Base64 string differ from the one another tool produced?
The usual causes are a different text encoding (UTF-8 versus UTF-16 or Latin-1), a trailing newline or space in the input, the URL-safe alphabet, or line wrapping every 76 characters. Compare the inputs byte for byte before assuming one tool is wrong.
Is standard Base64 safe to put in a URL?
Not directly. Plus may be read as a space in query strings, slash splits path segments and equals separates keys from values. Either percent-encode the string or use the Base64URL alphabet, which was designed for this purpose.