How to encode or decode Base64
To encode text: choose Encode, type or paste your text, and the Base64 result appears instantly.
To decode Base64: choose Decode and paste the Base64 string. You can also paste a full data: URL — the prefix is removed automatically. If the result is readable text, it’s shown directly; if it’s an image or other file, you’ll see a preview (for images) and a Download file button.
To encode a file: in Encode mode, scroll to Encode a file to Base64, choose any file up to 20 MB, and copy the result — optionally as a ready-to-use data: URL.
Common uses
- Embedding images in HTML or CSS as data URLs, e.g.
background-image: url(data:image/png;base64,...) - Sending binary data in JSON APIs, which only support text
- Inspecting tokens — the parts of a JWT are URL-safe Base64 encoded JSON
- Email attachments, which are Base64-encoded behind the scenes
- Basic authentication headers, which encode
username:passwordin Base64 - Debugging encoded values in logs, cookies and configuration files
How Base64 works
Base64 takes the input bytes three at a time (24 bits) and splits them into four groups of 6 bits. Each 6-bit value (0–63) is mapped to one of 64 characters. If the input length isn’t a multiple of three, the output is padded with =.
Because 3 bytes become 4 characters, Base64 output is about 33% larger than the original data. That’s why embedding large images as data URLs is usually a bad idea for performance — it works best for small icons and assets.
Standard vs URL-safe
| Variant | Characters 62 and 63 | Padding | Used in |
|---|---|---|---|
| Standard | + and / |
= |
Email, data URLs, most APIs |
| URL-safe | - and _ |
Usually omitted | JWT, URLs, file names |
The decoder accepts both variants automatically, and also tolerates missing padding, spaces and line breaks — common when copying Base64 from emails or logs.
Base64 is not encryption
It’s worth repeating: Base64 hides nothing. It only changes how data is written so it can travel safely through systems that expect text. Anyone can decode it in a second. To protect secrets, use real encryption, and treat Base64-encoded credentials (for example in basic auth headers) with the same care as plain text.
Troubleshooting
- “Not valid Base64” — the input contains characters outside the Base64 alphabet. Check for stray quotes or text around the encoded value.
- “Invalid length” — the string was probably cut off when copying.
- Decoded output looks like gibberish — the data is binary, or was encoded with a different text encoding. Use Download file to save the raw bytes.
Image to Base64 (data URLs)
To embed a small image directly in HTML or CSS, encode the image file with As data: URL enabled and copy the result. You can then use it like this:
- In HTML:
<img src="data:image/png;base64,iVBOR..." alt=""> - In CSS:
background-image: url("data:image/png;base64,iVBOR...")
This saves a separate network request, which can help for tiny icons. For anything larger than a few kilobytes, a normal image file is better: it can be cached separately and doesn’t bloat your HTML or CSS by a third. Inline images also can’t be lazy-loaded or shared between pages, so reserve data URLs for small icons, placeholders and email templates where external images may be blocked. As a rough guide, keep inline images under about 4 KB, and switch to a regular image file for anything larger than that.
Private and local
All encoding and decoding runs in your browser — useful when you’re working with tokens, credentials or private files that shouldn’t be pasted into a website that sends them to a server. To pretty-print decoded JSON, use the JSON Formatter.