Image ↔ Base64
Convert an image to a data URL, or restore Base64 into an image.
What is Image ↔ Base64
Image ↔ Base64 converts an image file into a Base64 data URL (data:image/...;base64,...), or restores pasted Base64 back into a previewable, downloadable image. Handy for inlining small icons in HTML or CSS. Everything runs in your browser; the file is never uploaded (4 MB limit).
File
🔒 Everything runs in your browser. Nothing is uploaded.
What this tool actually does with your file
- Where it runs
- In your browser, on this page
- Upload
- None — the file never leaves your device
- Offline
- Works with the network disconnected
Turning an image into a data URI
The file is read with FileReader as a data URL, giving data:image/png;base64,… That string can be placed directly into an img src or a CSS background with no network request, which is the entire appeal: one fewer round trip and no broken-image flash on load.
The cost is size. Base64 inflates by about a third, and the image cannot be cached separately, cannot be loaded in parallel, and blocks the render of whatever contains it. Under roughly 2 KB inlining usually wins; above that the extra bytes and the lost caching almost always lose, and well above that it visibly hurts first paint.
Where the string breaks
Data URIs in CSS need quoting discipline: a base64 body contains no quotes, but the surrounding url() still needs the right syntax, and a stray line break inserted by a formatter breaks the value. In HTML attributes, very long values are legal but unreadable, and some templating engines truncate them.
Email clients are the other trap. Many strip data URIs entirely, so an inlined icon that works on the web disappears in the newsletter. For HTML email, host the image and reference it by URL.
When to use a file instead
Keep the image as a file if it appears on more than one page, if it is larger than a few kilobytes, or if it needs cache headers, responsive variants or a CDN. The data URI approach is for one-off, tiny, render-critical assets — a favicon fallback, a spinner, a single decorative mark.
Also check the MIME type in the prefix against the actual bytes. A PNG that announces itself as image/jpeg will still render in most browsers (they sniff), but image processing pipelines downstream will fail on it, and the failure is far from the line that caused it.
How to use it
- 1.Pick a direction (Encode / Decode)
- 2.Encode: choose a file. Decode: paste Base64
- 3.Run, then copy or download the result
How Image ↔ Base64 works under the hood
Encoding tools convert between representations of the same bytes: Base64, percent-encoding, hex, HTML entities, Unicode escapes. A correct encoder is reversible; a lossy one silently changes the data.
- 1
Get the exact bytes
Text is encoded to UTF-8 bytes with TextEncoder first; binary input is read as an ArrayBuffer. Encoding the wrong byte sequence is the most common cause of a wrong result.
- 2
Apply the encoding rule
Each format has an exact specification: Base64 uses a 64-symbol alphabet with padding, percent-encoding escapes reserved characters as UTF-8 bytes.
- 3
Decode back to verify
Round-tripping the output back to the input is the only honest proof that an encoder is correct. The tool keeps the reverse path available on the same page.
Processing pipeline
Base64 is not encryption
Base64 increases size by about a third and hides nothing: anyone can decode it. It exists to carry binary data through text-only channels such as JSON, email headers and data URLs. If you need confidentiality, use encryption with a key, not an encoding.
Where encoders break
Percent-encoding applied twice turns %20 into %2520; Base64 without padding fails strict decoders; UTF-16 input decoded as UTF-8 produces replacement characters that cannot be recovered. When output looks wrong, check the byte sequence before checking the tool.
Verify it yourself
Encoders are pure functions over bytes. Decode the output again and you should get the input back exactly.
- 1.Open DevTools on this page and switch to the Network tab
- 2.Keep the filter on Fetch/XHR and run the tool
- 3.Confirm no request carries your file — you should see only page assets and fonts
Frequently asked questions
Where can I use the data URL?
Paste it into an <img src> or CSS url(). Inlining small icons saves HTTP requests, but for large images the size grows by roughly 33%, so keep inlining to small assets.
Which formats are supported?
PNG, JPEG, GIF, WebP, SVG, BMP and ICO. When decoding, the format is detected from the first bytes of the Base64 payload.
What this kind of conversion cannot keep
Encoding and hashing run through the browser's Web Crypto API or a pure-JavaScript implementation. The output is deterministic: the same input always produces the same digest, so you can verify a result against any other tool.
More in Encoding
On this page
- What is Image ↔ Base64
- What this tool actually does with your file
- How it actually behaves
- How to use it
- How it works inside
- Frequently asked questions
Excel formula reference
29 functions with syntax, arguments and a table you can retype.
Browse the list →