Base64 Encoder & Decoder
Encode and decode Base64 online. Convert text to Base64 or decode Base64 back to readable text, with a URL-safe mode for tokens, filenames, and URLs.
What is Base64 encoding?
Base64 is a binary-to-text encoding, defined in RFC 4648, that represents any sequence of bytes using 64 printable ASCII characters (A–Z, a–z, 0–9, + and /), with = used for padding. It does not compress or encrypt anything — it re-encodes bytes into a form that survives systems built for plain text, such as email (MIME), JSON payloads, HTTP headers and configuration files.
Every 3 bytes of input become 4 Base64 characters, so encoded output is about 33% larger than the original. When the input length is not a multiple of 3, the last group is padded with one or two = signs. Decoding reverses the process exactly, with no loss. For a longer walk-through, read Base64 explained.
How to use the Base64 encoder and decoder
- Type or paste text into the Input pane.
- Tick URL-safe (- _, no padding) if the result is going into a URL, filename or token.
- Click Encode to turn the text into Base64, or Decode to turn Base64 back into text.
- Use Copy, or Download to save the result as
base64-result.txt. Clear empties both panes.
Options and behaviour explained
- Encode — converts your text to UTF-8 bytes first, then to Base64. Accented letters, other scripts and emoji are therefore encoded correctly (
cafébecomesY2Fmw6k=). - Decode — removes spaces and line breaks, adds any missing
=padding, decodes to bytes and reads those bytes as UTF-8 text. Wrapped Base64 (for example from a PEM file or an email) can be pasted as it is. - URL-safe (- _, no padding) — when encoding, produces Base64url (RFC 4648, section 5):
+becomes-,/becomes_, and trailing=is dropped. When decoding, input containing-or_is recognised as Base64url automatically, whether or not the box is ticked.
This page works on text. It has no file upload, and Decode only shows output that is valid UTF-8 text. To turn an image into Base64 or a data URI, use the Image to Base64 tool.
Examples
| Input | Base64 (standard) | Base64 (URL-safe) |
|---|---|---|
Hello, World! | SGVsbG8sIFdvcmxkIQ== | SGVsbG8sIFdvcmxkIQ |
user:pass123 | dXNlcjpwYXNzMTIz | dXNlcjpwYXNzMTIz |
{"a":1} | eyJhIjoxfQ== | eyJhIjoxfQ |
?>? | Pz4/ | Pz4_ |
café | Y2Fmw6k= | Y2Fmw6k |
👍 | 8J+RjQ== | 8J-RjQ |
The padding pattern is easy to see with short inputs: Man (3 bytes) encodes to TWFu with no padding, Ma to TWE= and M to TQ==. The ?>? row shows why URL-safe mode exists: the standard alphabet produces a /, which would break a URL path.
Common uses of Base64
- Data URIs — embedding small images or fonts in CSS or HTML (
data:image/png;base64,...). - HTTP Basic authentication — the
Authorization: Basicheader carriesusername:passwordin Base64. - JSON Web Tokens — the header and payload are Base64url-encoded JSON; the JWT Decoder reads them for you.
- Email attachments — MIME encodes binary attachments as Base64 text.
- Binary in text-only fields — environment variables, configuration files or APIs that only accept strings.
Decoding a data URL such as data:text/html;charset=utf-8;base64,
A data URL carries a whole file inside the address itself: data:, the media type (for example text/html;charset=utf-8 or image/png), ;base64, and then the Base64-encoded content. You meet them in HTML and CSS, in links copied out of developer tools, and in phishing emails that hide a page inside a link. Paste the complete data URL above and press Decode: the prefix is removed and the content after the comma is decoded, so data:text/html;charset=utf-8;base64,PGgxPkhlbGxvPC9oMT4= becomes <h1>Hello</h1>. The decoded HTML is shown as text and never opened or run, which also makes this a safe way to see what a suspicious data link contains.
To build a data URL, encode your HTML or text here and put data:text/html;charset=utf-8;base64, in front of the result. For images, the image to Base64 converter writes the complete data URL for you. Data URLs whose content is percent-encoded rather than Base64 (no ;base64 in the prefix) are URL-encoded text: decode those with the URL encoder and decoder.
Common errors and how to fix them
Failed decodes are reported above the panes and in the Output pane, starting with Invalid Base64 input:. The rest of the message comes from your browser, so its wording differs between Chrome, Firefox and Safari.
| Symptom | Cause | Fix |
|---|---|---|
| Error about an invalid or incorrectly encoded character | The input contains characters outside the Base64 alphabet, such as $, quotes or surrounding JSON. | Paste only the Base64 text. A data:...;base64, prefix is fine: Decode removes it for you. |
| Error about data that is not valid UTF-8 | The Base64 is valid but encodes binary data (an image, a ZIP, a compressed or encrypted value), not text. | Decode it with a tool or library that writes bytes to a file instead of showing text. |
| Error on a value of 1, 5, 9… characters | A length that leaves one character over can never be valid Base64; the string was probably cut off. | Copy the full value again. |
| Encoded result differs from another tool | The other tool used URL-safe mode, kept or dropped padding, or encoded text in a different character set. | Match the URL-safe setting; this tool always encodes text as UTF-8. |
Frequently asked questions
Is Base64 encoding the same as encryption?
No. Base64 is a reversible encoding, not encryption. Anyone can decode a Base64 string without a key or password, so never rely on it to protect passwords, tokens or personal data.
What is URL-safe Base64?
Standard Base64 uses +, / and =, which have special meanings in URLs and are awkward in filenames. URL-safe Base64 (Base64url) swaps + for - and / for _, and usually omits padding. JWTs use it for all three segments.
Why is my Base64 output bigger than the input?
Each Base64 character carries 6 bits, so 3 bytes need 4 characters — about a third more, plus up to two padding characters. Non-ASCII text grows further because it takes 2–4 bytes per character in UTF-8 before encoding.
Should I use Base64 or hexadecimal?
Both turn bytes into text. Hexadecimal uses two characters per byte, so it doubles the size but is easy to read byte by byte — Hi! is 486921. Base64 uses four characters per three bytes (SGkh), so it is more compact and is the usual choice for data URIs, email and tokens. Hashes and checksums are more often shown in hex.
Do I need the = padding at the end?
Padding makes the length a multiple of 4, but the data can be decoded without it. This tool adds missing padding automatically when decoding. Some other decoders are strict, so keep the padding when the receiving system expects standard Base64.
Why does my decoded text look wrong or fail?
Usually the input is incomplete, has extra characters around it, or encodes binary data rather than text. This tool reads decoded bytes as UTF-8 and reports an error rather than showing garbled characters when they are not valid UTF-8.
Is my data sent to a server?
No. Encoding and decoding use your browser's built-in functions, and the text you enter is not sent anywhere by the tool.
Guides
How JSON Web Tokens Work: Claims, Signatures and Common Mistakes
What is inside a JWT, how the signature is checked, which claims matter and the mistakes that make tokens insecure.
Base64 Encoding Explained: Padding, Base64URL and When to Use It
How Base64 turns bytes into text, why it adds padding and a third to the size, how Base64URL differs, and why it is not encryption.
URL Encoding Explained: Percent-Encoding, encodeURIComponent and +
Which characters must be percent-encoded, encodeURI versus encodeURIComponent, + versus %20, double encoding and encoding in other languages.