Base64 Encoder & Decoder
Type in either box to encode text as Base64 or decode Base64 back into text. UTF-8 safe, with a URL-safe alphabet option.
How to Use
- Type or paste text into the top box and the Base64 result appears in the bottom box.
- Paste Base64 into the bottom box to decode it in the top box. There's no encode or decode button to pick, and a missing trailing =, stray spaces, or line breaks are all fine.
- For JWTs or values going into a URL, choose the URL-safe alphabet: it uses - and _ instead of + and /, and encoding leaves off the = padding.
- If the decoded bytes aren't valid UTF-8, the top box still shows what could be read and warns that this may be binary data such as an image or archive, along with a hex preview of the raw bytes.
- If something is wrong, the box with the problem shows which character it is, and the other box keeps its last good result. “Select the problem” highlights that part for you.
- “Swap” moves the result into the box you typed in. “Clear” empties both boxes.
Where you run into Base64
Base64 does one job: it turns arbitrary bytes into a string made only of letters, digits, and a couple of symbols, so the data can travel through channels that can only handle plain text. In day-to-day work you meet it in places like these:
- JWTs: the three-part login tokens separated by dots. The first two parts are Base64. Paste eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 and you get {“alg”:“HS256”,“typ”:“JWT”} back. It uses the URL-safe alphabet, so choose “URL-safe” before decoding.
- Data URIs: an inline image in CSS or HTML that starts with data:image/png;base64, followed by a long Base64 string. For a whole image file, use the Image to Base64 tool instead. This one is built for text.
- HTTP Basic authentication: the value after “Basic” in an Authorization header is “username:password” in Base64. dXNlcjpwYXNz decodes to user:pass, and anyone who can see the header can read it, which is why it must only be sent over HTTPS.
- Email attachments: email was designed for text, so attachments are converted to Base64 and placed inside the message. This scheme is called MIME, and lines are normally wrapped at 76 characters.
- Config files and certificates: Kubernetes Secret values and PEM certificates and keys are binary data wrapped in Base64.
- APIs and database fields: JSON can’t hold raw binary, so APIs that return file contents, signatures, or hash values often send them as Base64 strings.
In every one of these cases, Base64 is only the packaging. What’s inside is anyone’s guess until you unwrap it.
How the encoding works, and why there’s an equals sign at the end
Base64 takes 3 bytes at a time, which is 24 bits, and splits them into four groups of 6 bits. Each group maps to one of 64 characters. So 3 bytes become 4 characters, and the output is one third larger than the input.
| Input | Bytes | Output | Characters | Why |
|---|---|---|---|---|
Man |
3 | TWFu |
4 | One complete group, no padding |
Ma |
2 | TWE= |
4 | One byte short, so one = |
M |
1 | TQ== |
4 | Two bytes short, so two = |
Hello |
5 | SGVsbG8= |
8 | The last group has only 2 bytes |
The output length is always a multiple of 4, and the = signs fill the gap, so there are never more than two. Padding only keeps the length tidy. The decoder already has enough information without it, which is why many systems leave it out. When decoding, this tool accepts missing = signs, spaces, and line breaks as they are. When encoding, the standard alphabet adds the padding and the URL-safe alphabet doesn’t.
If the input has a problem, the tool tells you which character is the culprit. Three causes are the most common: a character that isn’t in the alphabet, such as mixing the standard and URL-safe alphabets; data that continues after an = sign; and a count of valid characters that leaves a remainder of 1 when divided by 4. That last length can never come from whole bytes, so part of the string was almost certainly cut off when it was copied.
Why btoa fails on Chinese and emoji and mangles accents
The browser’s built-in btoa function only accepts characters that fit in a single byte, which means the Latin-1 range. Chinese text, emoji, and the € sign make it throw an error. Accented letters such as é and ñ get through, but each one is encoded as a single byte, so the result doesn’t match UTF-8. People then work around it in ways that produce garbled output. The correct approach is to convert the text to bytes first and encode those bytes. This tool uses UTF-8 for that step.
| Text | UTF-8 bytes | Base64 | Characters |
|---|---|---|---|
Hello |
5 | SGVsbG8= |
8 |
日本語 |
9 | 5pel5pys6Kqe |
12 |
こんにちは |
15 | 44GT44KT44Gr44Gh44Gv |
20 |
😀 |
4 | 8J+YgA== |
8 |
Plain English letters take one byte each, but accented letters such as é take two, most Chinese, Japanese, and Korean characters take three, and emoji usually take four. That is why non-English text produces longer Base64 than you might expect.
Keep in mind that Base64 doesn’t know which character encoding the original text used. If the string was produced from text in an older encoding such as Windows-1252 or Shift_JIS, decoding it as UTF-8 won’t give a valid result. The tool still shows whatever it can read, and warns that the bytes may not be UTF-8. If the data turns out to be a file, the hex preview lists up to the first 64 bytes, and the opening bytes usually reveal the file type:
| Opening bytes | Base64 starts with | File type |
|---|---|---|
| 89 50 4E 47 | iVBORw |
PNG image |
| FF D8 FF | /9j/ |
JPEG image |
| 25 50 44 46 2D | JVBERi |
PDF document |
Base64 is not encryption, and it’s not hashing
You’ll often see phrases like “Base64 encryption” or “Base64 decrypt” online, and they cause real confusion. Base64 is an encoding. Its rules are public, there is no key, and anyone can reverse it instantly. It looks like gibberish to a person, but that doesn’t make it unreadable to anybody else.
| Technique | Can it be reversed? | Needs a key? | What it’s for |
|---|---|---|---|
| Encoding, such as Base64 | Yes, by anyone | No | Fitting data into places that only accept text |
| Hashing, such as SHA-256 | No | No | Checking whether data has been changed |
| Encryption, such as AES | Only with the key | Yes | Keeping content away from other people |
Three mistakes show up again and again in real projects:
- Storing a password or personal data in a database or config file after only converting it to Base64. That is the same as storing it in plain text.
- Assuming a Kubernetes Secret is safe because its values are Base64. The Base64 is just the format. Protection comes from access control and additional encryption.
- Hiding an API key by Base64-encoding it in front-end code. Anyone with the browser’s developer tools can reverse it in seconds.
Base64 often shows up next to hashing and encryption, because hash values and ciphertext are also bytes. When they need to go inside JSON or a URL, Base64 turns them into text. In that setup Base64 only makes the data portable, while hashing and encryption do the verifying and the hiding. If you really need to protect content, use encryption such as AES, or the Password-Protect Text tool.
What to check when the result looks wrong
If the decoded output isn’t what you expected, work through these points first:
- Wrong alphabet: a string containing - or _ is URL-safe, and one containing + or / is standard.
- Plus signs turned into spaces: in URL parameters, a + can be read as a space. If the result looks broken, put the + signs back, or encode with the URL-safe alphabet next time.
- Extra prefix or quotes: for a data URI, remove everything up to and including data:image/png;base64, and for a JSON string, remove the quotation marks around it.
- Garbled text: look for the “not valid UTF-8” warning. If it appears, the data is most likely a binary file or text in an older encoding, and the hex preview will help you tell which.
- A truncated string: long strings pasted from a phone or chat app often lose their ending. The tool points at the spot where the length can’t form whole bytes.
FAQ
What is Base64 and when is it used?
Base64 represents any data using 64 printable characters (A–Z, a–z, 0–9, +, /), so images, binary data, or text with special symbols can travel safely inside JSON, email, URLs, or source code. Every 3 bytes become 4 characters, so the output is about a third larger. You'll meet it in JWTs, data URIs, and many APIs.
Is Base64 encryption? Can it protect my data?
No. Base64 is an encoding: it follows a public rule, and anyone can decode it without a key. It hides nothing, even though people often call it “Base64 encryption”. To protect content, use real encryption, and never leave a password or personal data merely Base64-encoded.
Will accents, Chinese, Japanese, or emoji get garbled?
No. The tool treats text as UTF-8, so any language and emoji encode and decode correctly. If the Base64 was produced from text in another character encoding, such as Windows-1252, decoding shows garbled characters and the tool warns that the result isn't valid UTF-8.
What's the difference between the standard and URL-safe alphabets?
The standard alphabet uses + and / and pads with =. The URL-safe alphabet uses - and _ instead, so the result can go into a URL without percent-encoding. JWTs use it, and usually drop the = padding too. Every other character is the same. If you pick the wrong alphabet when decoding, the tool points at the first character that doesn't fit.
What does “not valid UTF-8” mean when decoding?
The decoded bytes can't be read as text. Usually the Base64 actually holds binary data such as an image, PDF, or archive, or the original text used an older character encoding. The tool doesn't fail. It still shows the result, with � for unreadable bytes, plus a hex preview of the raw bytes so you can judge. For example, bytes starting with 89 50 4E 47 are a PNG image.
Related Tools
Image to Base64
Choose an image to get a Data URI and plain Base64 with the size change, or paste Base64 to preview the image and download it.
URL Encoder & Decoder
Type in either box to percent-encode text for a URL, or decode %20-style sequences back into readable text.
HTML Entity Encoder & Decoder
Type in either box to turn text into HTML entities, or decode < & 中 and other entities back into text. All named entities supported.
Unicode Escape Encoder & Decoder
Type in either box to turn text into \uXXXX, \u{…}, &#x…;, or U+XXXX, or decode any mix of Unicode escapes back into text.
JSON to YAML Converter
Paste into either box to convert JSON to YAML or YAML back to JSON. Big numbers stay exact, and every lost detail gets its own warning.
JSON to TOML Converter
Paste text or open a file in either box to convert between JSON and TOML (including pyproject.toml and Cargo.toml), with per-path warnings for any lost details.
Base Converter
Type in any field to convert between bases 2, 8, 10, 16, and any base from 2 to 36, with big numbers, negatives, repeating fractions, and two's complement.
Text to Binary & Hex Converter
Type in either box to turn text into the binary, octal, decimal, and hex of each UTF-8 byte, or decode those bytes back into text.
Morse Code Translator
Type in either box to turn text into Morse code or decode dots and dashes back into text, then play it as sound at the speed you choose. Includes Japanese Wabun.
Hash Generator
Enter text or choose a file to get MD5, SHA-1, SHA-256, SHA-384, and SHA-512 at once. Paste an expected value to see which algorithm matches.
Password Generator
Generate strong random passwords in one click. Choose the length and character types, up to 10 at a time.
QR Code Generator
Turn a URL, text, Wi-Fi network, phone number, or email into a QR code instantly. Download as PNG or SVG.