Base64 Encoder & Decoder
Encode text to Base64 or decode Base64 back to text. Supports UTF-8 and Unicode.
Paste text or a file and click Encode to get Base64 output, or paste Base64 and click Decode to recover the original. Works offline, your data never leaves your browser.
Use Base64 for transport formats such as JSON, email, and data URIs, not for hiding secrets.
What Is Base64 and When Do You Need It?
Base64 is a way of representing binary data using only text characters. It converts raw bytes into a string of letters, numbers, plus signs, and slashes, characters that survive being passed through systems that only handle text (like email, JSON, or HTML).
Think of it like spelling out a phone number in words: "oh-seven-seven-oh" instead of 0770. The information is the same, just represented in a text-safe format. The trade-off? Base64 output is about 33% larger than the original data. That's the cost of text-safety.
Important: Base64 is encoding, not encryption. Anyone can decode it instantly. Never use Base64 to "hide" passwords, tokens, or sensitive data, it provides zero security.
Common Base64 Use Cases
| Use Case | Why Base64? | Example |
|---|---|---|
| Data URIs in HTML/CSS | Embed small images directly in code | <img src="data:image/png;base64,..."> |
| Email attachments (MIME) | SMTP only handles 7-bit ASCII text | Content-Transfer-Encoding: base64 |
| JSON payloads | JSON can't contain raw binary | {"file": "SGVsbG8..."} |
| JWT tokens | Header and payload are Base64URL encoded | eyJhbGciOiJIUzI1NiJ9... |
| HTTP Basic Auth | Credentials encoded (not encrypted!) | Authorization: Basic dXNlcjpwYXNz |
| SVG in CSS | Inline SVG backgrounds without extra requests | background: url("data:image/svg+xml;base64,...") |
What this means for you: If you're embedding small icons (under 2KB) in CSS, Base64 data URIs save HTTP requests. For anything larger, a regular image file with proper caching is more efficient.
Base64 vs Other Encodings
| Encoding | Characters Used | Size Overhead | Best For |
|---|---|---|---|
| Base64 | A-Z, a-z, 0-9, +, / | +33% | Binary data in text contexts |
| Base64URL | A-Z, a-z, 0-9, -, _ | +33% | URLs, JWTs (no +/= characters) |
| Hex | 0-9, a-f | +100% | Hash digests, colour codes |
| URL encoding | %XX format | Variable | Special characters in URLs |
Common Base64 Mistakes
Using Base64 for "security". Base64 is trivially reversible. Encoding a password or API key in Base64 provides zero protection. Use proper encryption (AES) or hashing (bcrypt) for sensitive data.
Base64-encoding large images in CSS. A 50KB image becomes 67KB as Base64, and it can't be cached separately from the stylesheet. Only inline images under 2KB, anything larger should be a regular file with HTTP caching.
Mixing Base64 and Base64URL. Standard Base64 uses + and / which break in URLs. JWTs use Base64URL (with - and _ instead). Decoding one with the other's alphabet produces garbage. Check which variant you need.
How to Read Base64 Output
Base64 output looks random, but it has a strict structure. Each group of four Base64 characters represents three original bytes. Padding with = appears only at the end, and only when the input length is not divisible by three.
| Input | Bytes | Base64 | What to Notice |
|---|---|---|---|
| f | 1 | Zg== | Two padding characters because only one byte was available |
| fo | 2 | Zm8= | One padding character because two bytes were available |
| foo | 3 | Zm9v | No padding because the input filled a full three-byte group |
| Hello | 5 | SGVsbG8= | The final = shows that the last group had two input bytes |
Padding is not extra data. It tells the decoder how many bytes to recover from the final four-character group.
If padding is missing, restore it only at the end of the string, never in the middle.
Validating a Base64 String
Check the alphabet
Standard Base64 should contain only letters, digits, +, /, and trailing = padding. Whitespace is sometimes wrapped into long MIME output, but it is not part of the encoded data.
Check the length
A padded Base64 string should have a length divisible by four. If it does not, it may be missing padding or may be Base64URL from a token or URL-safe format.
Check the variant
A JWT segment usually uses Base64URL, so it may contain - and _ instead of + and /. Convert the alphabet before using a strict standard Base64 decoder.
Check the decoded bytes
Decoding can succeed even when the result is not readable text. Images, PDFs, ZIP files, and encrypted blobs are binary data, so inspect them with the right file tool.
Base64 in Data URIs
A data URI combines a media type, an optional charset, and the encoded payload. The browser treats it like an inline file. This is useful for tiny assets, but it is a poor fit for large images because the encoded text grows and cannot be cached as a separate resource.
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==
| Part | Meaning |
|---|---|
| data: | Signals that the URL contains inline data rather than an external address |
| image/svg+xml | Declares the MIME type so the browser knows how to interpret the bytes |
| ;base64 | Declares that the payload is Base64 encoded |
| , | Separates metadata from the encoded payload |
Encoding Text Correctly
Plain ASCII examples are simple, but real text often includes accents, symbols, right-to-left scripts, or emoji. JavaScript's old btoa() function expects byte-style Latin-1 text, so direct encoding can fail for characters outside that range.
| Text | Encoding Detail | Why It Matters |
|---|---|---|
| cafe | ASCII letters only | One byte per character |
| cafeΜ | May include a combining accent | Looks similar, but byte length can differ |
| ζ±δΊ¬ | UTF-8 uses three bytes per character | Needs byte-aware encoding before Base64 |
| π | UTF-8 uses four bytes | Old ASCII-only snippets fail on emoji |
This page uses TextEncoder and TextDecoder so Unicode text is converted through UTF-8 bytes first.
Practical Debugging Checklist
If decoding fails
Look for copied quotes, missing padding, line wrapping, or a URL-safe alphabet. A common fix for JWT segments is to replace - with +, replace _ with /, then restore padding to a multiple of four.
If output looks broken
The decoded bytes may not be UTF-8 text. Try saving the bytes as the expected file type, or inspect the first bytes for file signatures such as PNG, PDF, ZIP, or GIF.
If the payload is too large
Prefer a file upload, object storage URL, or streaming transfer. Large Base64 strings are harder to diff, harder to cache, and can make JSON payloads expensive to parse.
Related Tools
How to use this tool
Enter text or Base64 string in the input
Click Encode or Decode
Copy the result or swap input/output
Common uses
- Embedding small images in HTML/CSS as data URIs
- Encoding binary data for JSON payloads
- Decoding JWT token components
- Preparing email attachments for MIME transport
- Converting files for inline SVG backgrounds
Share this tool
Frequently Asked Questions
What is Base64 encoding?
Is Base64 encryption?
Does this tool support Unicode and emojis?
What's the difference between Base64 and Base64URL?
Why does Base64 make data 33% larger?
When should I use Base64 data URIs vs regular images?
How do I Base64 encode in JavaScript?
Can I encode files and images to Base64?
What characters are valid in Base64?
Why is Base64 used in email (MIME)?
Is my data sent to a server?
What's the maximum size I can encode?
Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.