Free Base64 Encoder & Decoder
Convert text to Base64 and back with full UTF-8 support. URL-safe mode, line wrapping and file input included — all in your browser.
Input
é, ñ, 中文 and emoji correctly — things that native btoa() throws on.Output
What Is Base64?
Base64 is a way of representing binary data using 64 printable ASCII characters: A–Z, a–z, 0–9, + and /. It was designed for systems that can only carry text — email, JSON, XML, HTML attributes and CSS values — but sometimes need to transport binary content.
Base64 is not encryption. It's a lossless encoding — anyone can decode it. It's also not compression — it makes data ~33% bigger. It's just a way to turn binary into text so it can pass through text-only channels without corruption.
The 64-character alphabet
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Every 3 bytes of input (24 bits) become 4 characters of output (24 bits split into 4 × 6 bits). When the input length isn't a multiple of 3, the last group is padded with = characters to keep the output aligned:
| Input bytes | Output chars | Padding |
|---|---|---|
| 3 | 4 | None |
| 2 | 3 + 1 pad | One = |
| 1 | 2 + 2 pads | Two == |
Why does btoa() fail on Unicode?
JavaScript's native btoa() function only accepts strings where every character is in the range 0–255 (Latin-1). Any character above that — é, ñ, 中, 😀 — throws:
Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
This tool avoids the problem by converting the string to UTF-8 bytes first, then feeding those bytes to btoa():
var bytes = new TextEncoder().encode(str); // string → UTF-8 bytes
var binary = '';
for (var i = 0; i < bytes.length; i++) {
binary += String.fromCharCode(bytes[i]);
}
var base64 = btoa(binary);
Decoding does the reverse with TextDecoder. The result is correct Base64 for any Unicode string.
Standard vs URL-safe Base64
| Variant | Chars 62 & 63 | Padding | Used by |
|---|---|---|---|
| Standard (RFC 4648) | + and / | = | MIME, data URIs, most APIs |
| URL-safe (RFC 4648 §5) | - and _ | Often omitted | JWT, OAuth, URLs, filenames |
The characters +, / and = have special meaning in URLs and filenames, so URL-safe Base64 swaps them out. This tool converts automatically.
Line wrapping (MIME)
Email attachments and some legacy systems expect Base64 output wrapped at 76 characters per line. Other systems require a single long line. The line wrap option is off by default because most modern contexts handle unwrapped output fine.
Common use cases
Data URIs
Embed small images in HTML or CSS as data:image/png;base64,….
HTTP Basic Auth
Encode username:password for the Authorization: Basic header.
JWT Payloads
Inspect or construct the URL-safe Base64 segments of a JSON Web Token.
API Payloads
Send binary data inside a JSON POST body without multipart uploads.
Email Attachments
Encode binary files for MIME transport.
Database Fields
Store small binary blobs in text columns.
Obfuscation
Hide spoilers or simple strings from casual inspection (not real security).
Debugging
Decode a Base64 string you found in a cookie, header or log file.
Privacy and security
This Base64 encoder runs entirely in your browser. Encoding uses native TextEncoder, String.fromCharCode and btoa; decoding uses atob and TextDecoder. Your text never leaves your device. Safe for credentials, API keys, private messages and any other sensitive content.
Frequently Asked Questions
What is Base64 encoding?
Does Base64 encoding make files bigger?
What is URL-safe Base64?
+ and / which have special meanings in URLs. URL-safe Base64 replaces + with - and / with _, and often strips the = padding. This makes the output safe to put directly in a URL query string, cookie or filename.Why does native btoa() fail on Unicode?
btoa() only handles Latin-1 characters (code points 0–255). Feeding it any Unicode character like é, ñ, or an emoji throws an InvalidCharacterError. This tool uses TextEncoder to convert the string to UTF-8 bytes first, then encodes those bytes.