Base64 encoder
This tool converts any UTF-8 text to Base64, with an optional URL-safe variant. It’s useful for embedding text in data URIs, building API payloads, constructing JWT-style segments, or any system that only accepts ASCII. Encoding runs entirely in your browser, so it’s safe for sensitive input.
How it works
The text is first turned into UTF-8 bytes with new TextEncoder().encode(text).
Those bytes are assembled into a binary string and passed to the browser’s native
btoa(), which produces standard Base64. Encoding via UTF-8 bytes first (rather
than calling btoa on the raw string) is what lets emoji and non-Latin
characters encode without errors. When URL-safe is on, the result is
post-processed: + becomes -, / becomes _, and trailing = padding is
stripped — the RFC 4648 URL-safe alphabet.
Example
| Input | Standard Base64 | URL-safe |
|---|---|---|
Hello | SGVsbG8= | SGVsbG8 |
a+b/c | YStiL2M= | YStiL2M |
café ☕ | Y2Fmw6kg4piV | Y2Fmw6kg4piV |
Base64 grows the data by about one third (3 bytes become 4 characters), so
Hello (5 bytes) becomes 8 characters before padding.
To reverse the process, use the Base64 decoder. Everything runs locally in your browser — nothing is uploaded.
Standard vs URL-safe: when each matters
| Scenario | Use standard Base64 | Use URL-safe Base64 |
|---|---|---|
| Email MIME attachments | Yes | No |
HTML data URI (src="data:...") | Yes | No |
| JWT header and payload | No | Yes |
| Query-string parameter | No | Yes |
| File name or path segment | No | Yes |
| HTTP cookie value | No | Yes (safest) |
Standard Base64 uses + and /, which have special meaning in URLs and query strings — + decodes as a space and / is a path separator. URL-safe Base64 swaps those for - and _, making the result safe to drop directly into a URL without percent-encoding. Padding (=) can also interfere with some URL parsers, which is why URL-safe Base64 typically omits it.
Common encoding mistakes to avoid
Encoding non-Latin text directly through btoa: Calling btoa("café") in JavaScript throws a DOMException because the French character é has a code point above 255. This tool encodes via UTF-8 bytes first, which is the correct approach and handles emoji and any non-ASCII script cleanly.
Treating Base64 as encryption: Base64 is encoding, not encryption. Anyone who can see the Base64 string can decode it instantly — it provides no confidentiality. Use it to represent binary data safely in text contexts, not to hide content.
Double-encoding: If you paste already-Base64-encoded text into this encoder, you get double-encoded output. Make sure you are starting from the original plaintext, not from an existing Base64 string.