Developer / Free browser tool
Base64 Encoder and Decoder
Two directions, converted as you type. Invalid characters, impossible lengths and bytes that are not valid UTF-8 are reported rather than turned into plausible-looking rubbish.
No account or install. Tool input is processed on your device.
URL-safe output swaps + for - and / for _, then drops the trailing =. Padding is added back automatically when decoding.
This text cannot be encoded.
This is not valid Base64.
About this tool
Base64 turns arbitrary bytes into the 64 characters that survive an email body, a JSON string, a URL or an XML attribute: A to Z, a to z, 0 to 9, plus and slash, with equals signs for padding. Three bytes become four characters, so a 1,000-byte payload arrives as 1,336 characters plus line breaks.
Most broken conversions are UTF-8 mistakes. JavaScript strings are sequences of UTF-16 code units, so an encoder that takes one character at a time mangles anything outside Latin-1. This converter encodes to bytes with TextEncoder first, so emoji and non-Latin scripts round-trip exactly: "é" is two UTF-8 bytes and encodes as w6k=, while the globe emoji is four bytes and encodes as eight characters.
The decoder reverses the order and is deliberately strict. It accepts whitespace, missing padding and the URL-safe variants of plus and slash, then validates the alphabet, the length and the padding before touching the bytes. If those bytes are not valid UTF-8, it says so instead of showing mojibake. Everything runs in this tab.
Why the UTF-8 step comes first
A JavaScript string is not a byte array. charCodeAt() returns a UTF-16 code unit, and the common btoa() one-liner throws above U+00FF or silently truncates if you mask the value. Both are wrong for real text: a Chinese character, an accented vowel and an emoji all occupy more than one byte in UTF-8. Encoding through TextEncoder turns the text into bytes that are identical on every platform, and the Base64 is computed over those bytes. Decoding reverses the order, with a fatal UTF-8 decoder, which is why a corrupt payload produces an error rather than replacement characters.
URL-safe output, padding and 76-character lines
RFC 4648 defines two alphabets. The standard one uses + and /; the URL-safe one (§5) substitutes - and _ and conventionally drops the trailing padding, because + means space in a query string and / ends a path segment. JWTs and many APIs use the URL-safe form. The decoder accepts either alphabet without being told which it is reading. Line wrapping is cosmetic: MIME (RFC 2045) wraps at 76 characters, PEM certificates use 64, and whitespace is ignored on the way back in.
What the decoder refuses
Four failures are reported separately: a character outside the alphabet, an impossible length (Base64 never leaves a remainder of one after division by four), padding that does not match the length, and bytes that are valid Base64 but not valid UTF-8. The last case catches people out: an image or an encrypted blob can be Base64-encoded, but it cannot be decoded into text. Use the image Base64 tool for pictures.
Base64 is an encoding, not encryption. Anyone who has the string can decode it, and it makes the payload about a third larger. It is a way to move bytes through text-only channels, not a way to protect them.
How it works
Pick a direction
The tabs switch between text and Base64 input. Swap direction carries the current output into the other box.
Set the alphabet
URL-safe output replaces + and / with - and _, and removes the padding. Wrapping at 76 characters is there for email and older MIME tooling.
Copy or download
The result updates on every keystroke. Copy puts it on the clipboard; Download writes a plain .txt file.
Common questions
Is Base64 encryption?
No. Encoding changes the representation, not the information, and there is no key. Anyone can decode a Base64 string with a browser console or a command-line tool. Use an authenticated encryption scheme for secrets; use Base64 when a channel only accepts text.
Why is the output about a third larger?
Base64 uses 6 bits per character, so 8-bit bytes need four characters for every three bytes: 4/3, or 33 percent overhead. Padding adds up to two more characters per line, and MIME line breaks add one character per 76. A 10 KB file becomes roughly 13.7 KB of text.
Why does the decoder reject Base64 that looks valid?
Because valid Base64 does not imply valid text. The bytes decode correctly but fail the UTF-8 check, which is the normal outcome for images, archives and encrypted data. The error message says exactly that instead of showing replacement characters.
When should I use the URL-safe alphabet?
Whenever the string goes into a URL, a filename, a cookie value or a JWT. The characters + and / have meaning in those contexts and may be escaped or truncated in transit. The URL-safe form swaps them for - and _ and drops the trailing equals signs.
Does the tool accept Base64 with missing padding?
Yes. Padding is added back internally after the alphabet and length checks. A string whose length is one more than a multiple of four is still rejected, because no amount of padding can rescue it.
Related tools
Image Base64
One page, both directions: a file becomes a data URI with ready-to-paste CSS and HTML, or a pasted string becomes an image again. The declared type is never trusted over the bytes.
JSON formatter
Paste JSON to indent it, compress it, sort its keys or find out why it will not parse. The output is built with JSON.parse and JSON.stringify, so it matches what a JavaScript runtime sees.
Timestamp converter
Paste an epoch value and read it six ways, or turn a date into seconds and milliseconds. The unit is detected, but never guessed silently.