Base64 Encoder / Decoder

Encode text to Base64 or decode Base64 back to text with correct UTF-8 handling for Chinese, emoji and multi-byte characters.

Loading tool…

How It Works

Base64 represents any byte sequence with 64 printable characters — A-Z, a-z, 0-9, + and / — plus = as padding. Three bytes become four characters, which is why valid output is always a multiple of four characters long. It is an encoding, not encryption: anyone with the string can decode it, so never use Base64 to protect a secret.

The browser's btoa function only accepts Latin-1 characters, which is why naive one-line Base64 snippets throw on Chinese text or emoji. This tool avoids the trap by converting your input to UTF-8 bytes with TextEncoder first and handing btoa a pure byte string. Encoding 你好 therefore encodes its six UTF-8 bytes into 5L2g5aW9, and a four-byte emoji such as 👋 round-trips intact as 8J+Riw==.

Decoding is forgiving about formatting but strict about data. Whitespace and line wraps from MIME-style output are stripped, URL-safe variants using - and _ are mapped back to + and /, and missing = padding is restored before the alphabet is validated. Characters outside the Base64 alphabet produce an "Invalid Base64 string" error. The rebuilt bytes then pass through a strict UTF-8 decoder, so bytes that are not valid UTF-8 fail with "Decoded bytes are not valid UTF-8" instead of rendering a page of U+FFFD replacement characters.

How to encode or decode Base64

  1. Choose Encode or Decode at the top of the tool.
  2. Paste your text (to encode) or Base64 string (to decode) into the input box.
  3. Copy the result from the output panel — padding and alphabet are handled for you.
  4. On a decode error, check for characters outside the alphabet or bytes that are not UTF-8.

Input to output at a glance

InputResultWhy
helloaGVsbG8=5 bytes become 8 characters with one pad sign
你好5L2g5aW96 UTF-8 bytes become 8 characters, no padding needed
👋8J+Riw==A four-byte emoji survives the round trip
aGVsbG8 (decode)helloMissing padding is restored before decoding
!!!! (decode)ErrorCharacters outside the alphabet are rejected

Examples

Input

hello

Output

aGVsbG8=

Five ASCII bytes encode to eight Base64 characters with one padding sign.

Input

你好

Output

5L2g5aW9

Six UTF-8 bytes encode without padding — UTF-8 safety is the core feature here.

Input

aGVsbG8 (decode mode)

Output

hello

Boundary: missing padding is restored automatically before decoding.

Input

!!!! (decode mode)

Output

Error: Invalid Base64 string

Boundary: characters outside the Base64 alphabet fail loudly instead of decoding to garbage.

Frequently Asked Questions

Does Base64 encrypt my data?
No. Base64 is a reversible encoding, not encryption — anyone can decode it without a key. Use it to move binary data through text-only channels, and rely on real cryptography (TLS, proper encryption) for secrecy.
Why does Base64 of Chinese text fail in other tools but work here?
The classic btoa function only accepts characters below code point 256. This tool converts text to UTF-8 bytes before encoding and decodes bytes back through a UTF-8 decoder afterwards, so multi-byte characters and emoji survive the round trip.
Can I decode Base64 that has line breaks or missing padding?
Yes. Whitespace and line wraps are stripped before decoding, URL-safe - and _ characters are treated as + and /, and missing = padding is restored automatically. Only characters that are genuinely outside the alphabet cause an error.
What is mojibake, and how does this tool avoid it?
Mojibake is the garbled text you get when bytes are decoded with the wrong character set — usually seen as � replacement marks. The decoder here runs in strict UTF-8 mode: invalid byte sequences raise an error instead of printing replacement characters.

Limitations & Accuracy

Encoding always emits the standard RFC 4648 alphabet with = padding; URL-safe - and _ are accepted on decode and normalized. Output grows by roughly a third: 3 bytes become 4 characters. Decoded bytes must form valid UTF-8 or decoding errors out — Base64 of other encodings (Latin-1 files, UTF-16) will not decode to readable text here. Base64 is not encryption.

Related Tools