Skip to main content

Base64 Encoder & Decoder – UTF-8-safe Conversion Online

Free Base64 encoding and decoding online: correct with UTF-8 and Chinese, URL-safe variant (- and _), instant both ways, no length limit. Runs in your browser, nothing uploaded.

Runs on your device — nothing is uploaded

Input characters
Output characters

Results appear here

Output:

Stuffing credentials into an API call, embedding a small icon in a page (data URI), peeking at a JWT's payload, tracing an email attachment's encoding — Base64 is the encoding you meet most often in day-to-day development, bar none. The conversion itself is mechanical; all the trouble hides in the details: Chinese text throws the moment you encode it, + turns into a space in URLs, and the padding = gets eaten by gateways.

This tool converts in both directions as you type: encode and decode share one input area (= switches the direction), and UTF-8 is correct the whole way — Chinese, emoji, any script goes through the standard path "text → UTF-8 bytes → Base64", never through btoa's Latin-1 shortcut.

How to Use

Enter your input

The text to encode or the Base64 string to decode — paste and the result appears, with no length limit. If the direction is wrong, press the switch (or the Decode button).

Switch on URL-safe when needed

Turn on the URL-safe switch when the result will sit in a URL or a filename: + becomes -, / becomes _ — both characters are reserved in URLs and some file systems, and the standard variant breaks there. When decoding, the same switch maps them back.

Copy the result

One click copies the output side. Encoded output carries standard padding (=); decoded output is restored as UTF-8, and Chinese and emoji come back exactly as they went in.

The Two Pitfalls Everyone Hits

Pit one: why Chinese fails to encode. The browser's native btoa() only accepts strings in the Latin-1 range — feed it Chinese and it throws InvalidCharacterError immediately. The "escape with btoa" recipe circulating online forces characters into Latin-1, and what it produces cannot be decoded back into Chinese by anyone else's decoder. There is exactly one correct path:

Step Operation What happens
1 TextEncoder().encode(text) The text becomes a sequence of UTF-8 bytes
2 bytes → binary string → btoa() Every 3 bytes become 4 Base64 characters
3 On the decode side, TextDecoder('utf-8') The bytes come back as the original text, via UTF-8

This tool walks exactly that standard path, and interops with any standard implementation — Python base64, openssl, and the rest.

Pit two: size inflation. Base64 encodes 3 bytes as 4 characters — the output is always 4/3 of the input (a touch more once padding is counted). Do not skip that arithmetic when embedding images: a 30KB image is 40KB of characters inside a data URI. The point of a transfer encoding is "moving binary safely through a text channel", not saving space.

URL-safe is an official Base64 variant (RFC 4648, section 5), not "a different encoding" — the alphabet swaps only two characters, and decoding swaps them back. A JWT's payload segment uses it: inside a signed token, + and / would break URL transport, so the ecosystem's uniform convention is URL-safe with the padding removed.

Frequently Asked Questions

Does the output match Python / openssl?

It does. Encoding takes the same standard path (UTF-8 bytes → the RFC 4648 alphabet), and any standard implementation decodes any other's output without ambiguity. Chinese that does not round-trip only happens with non-standard shortcuts like "escape/btoa" — this tool does not go there.

What happens when decoding fails?

An illegal character (one outside the alphabet) stops the decode from proceeding; the tool says so plainly instead of emitting half a result. Common causes, in order of likelihood: the trailing padding was lost in copying, URL-safe is on but the source is the standard variant (or the other way round), or you decoded text that had already been decoded once more.

Can it encode images or files?

No — this tool handles text only. Base64 for binary files (the openssl base64 kind of use on the command line, for example) needs to read the file's bytes first, and that is the pipeline of a file-handling tool. Text scenarios (JWTs, text inside data URIs, API credentials) are done here in one step.

Why does my JWT decode to gibberish?

A JWT's header and payload use the URL-safe variant — switch URL-safe on and try again. Implementations without padding (no trailing =) also decode fine: decoding groups by the actual character count, and padding only evens the length out to a multiple of 4 — it carries no necessary information.

Is there a length limit?

No hard limit — the conversion streams inside the browser. Text in the tens of KB (a whole page's source, a large JSON) converts in one go; for bigger batches, work in chunks.

Is what I paste uploaded?

No. Encoding and decoding are pure computation — zero network requests. Credentials and keys are exactly the sensitive strings that should not be handed to an online tool that posts back to a server; local processing is a hard requirement for that scenario.