Image to Base64

Image to data URI and back, in your browser. Live preview, the real gzipped size overhead, and ready-to-paste CSS, HTML and Markdown snippets.

Runs entirely in your browser — nothing is uploaded

Drop a file or click to browse

PNG, JPEG, GIF, WebP, AVIF, SVG, BMP, ICO — up to 8.0 MB. HEIC and TIFF are detected and flagged. Nothing is re-encoded: the URI carries your exact bytes.

About the Image to Base64

Drop an image in and get a data: URI back — the whole file encoded into one string you can paste straight into CSS, HTML, Markdown or JSON, with no separate request for the browser to make. Paste a URI in the other direction and the image comes back with a Save button. Nothing is re-encoded on the way through, so the round trip is byte-exact and the file you save is identical to the one you started with. The media type written into the URI comes from the file's magic numbers, not its extension: a .png that is really a JPEG gets labelled image/jpeg, and you are told about the rename.

Everyone knows Base64 adds about a third, because four characters carry three bytes. Almost nobody checks what survives compression — and that is the number that actually reaches a visitor. This tool gzips both sides and shows you. For already-compressed formats the overhead nearly evaporates: deflate codes Base64's 64-symbol alphabet in roughly the six bits Base64 wastes, so a 104 KB PNG that becomes a 136 KB URI is only about 4% larger over the wire. For SVG the result inverts. An SVG is markup full of repeated tags and attributes that gzip normally matches on, and Base64 shreds exactly those repeats: a typical 445-byte icon costs 307 bytes gzipped as a file, 445 as a Base64 URI, and 355 percent-encoded. So SVG is percent-encoded by default here, and the choice between the two encodings is made on measured gzipped size rather than string length — they disagree constantly, and the shorter string is regularly the bigger download.

A data URI is self-describing, and everything downstream believes the label rather than the bytes. Browsers do not — they sniff the content — so a URI that says image/png while carrying GIF bytes renders perfectly and can sit in a codebase for years. It breaks the first time it reaches something that trusts the header: a mail client, an image CDN, a PDF generator, a server echoing Content-Type. Both directions of this tool compare the declared type against the magic numbers and say so when they differ. The same check catches the other classic hand-built mistake — a URI assembled by string concatenation that forgot ;base64, whose payload then percent-decodes into believable garbage instead of failing outright.

Inlining is a trade, and the size warnings here mark where it stops paying. Under about 4 KB an image usually costs less as a URI than as a request. Past that, an inlined image cannot be cached on its own, is re-downloaded in full every time the HTML or stylesheet carrying it changes, cannot be lazy-loaded, and — inside a stylesheet — blocks the first paint of the entire page until it arrives. HTTP/2 also removed most of the request-count argument that made inlining popular in the first place. Two limits are worth knowing before you paste: Markdown is unreliable, because GitHub, GitLab and Reddit run rendered HTML through a sanitiser that drops data: URIs in image sources (VS Code, Obsidian and most static-site generators keep them); and HEIC and TIFF produce perfectly valid data URIs that no browser will ever paint, so those are detected and flagged rather than handed back as a broken image.

All of it runs in your browser through standard web APIs — reading the file, parsing its bytes, and encoding — and there is no server here to upload to. That matters more for this tool than for most: the images people inline are logos, brand assets, UI mockups and screenshots of internal dashboards, and pasting a client's unreleased artwork into an anonymous upload form to perform a byte transform your own machine does in a millisecond is a strange trade. You can confirm the claim rather than take it: open your devtools Network tab while you use the page, or switch off your Wi-Fi and watch it keep working.

Everything runs inside your browser using standard web APIs. Your data is never uploaded, never stored on a server, and never leaves your device — you can confirm that by opening your browser devtools Network tab, or by switching off your Wi-Fi and using the tool offline.

Frequently asked questions

Does gzip cancel out Base64's 33% overhead?

Mostly for already-compressed images, and not at all for SVG. Base64's waste is very regular — 64 symbols stored in 8-bit characters — and deflate's Huffman stage codes it back down to near six bits, so a PNG, JPEG or WebP data URI typically transfers only 3–5% larger than the file itself. SVG goes the other way: it is markup with repeated tags that gzip would normally match on, and Base64 destroys those repeats, so a Base64 SVG can transfer around 45% larger while the percent-encoded form transfers about 15% larger. Rather than quote a rule, this tool compresses both and shows the numbers for your specific file.

Should I use Base64 or percent-encoding for an SVG?

Percent-encoding almost always wins — but judge it on the gzipped size, not the string length. Percent-encoding is frequently the longer string and still the smaller download, because it leaves the markup intact for the compressor to work on. The tool measures both and picks the smaller transfer, and you can override it. The one case where percent-encoding is refused is an SVG that is not stored as UTF-8, such as a UTF-16 file: percent-encoding it would mean re-encoding the document rather than copying its bytes, so Base64 is used instead and the reason is shown.

Why doesn't my data URI image appear on GitHub or in an email?

Two different sanitisers. Markdown platforms — GitHub, GitLab, Reddit — strip data: URIs out of image sources when they render your Markdown to HTML, so the image silently vanishes with no error. Email is stricter still: Outlook and Gmail block data URIs in <img> outright, which is why marketing email always uses hosted images with absolute URLs. Data URIs are reliable in your own HTML and CSS, in VS Code and Obsidian previews, and in static-site generators that render Markdown themselves.

The URI says image/png but the file is really a JPEG. Does that matter?

In a browser, no — browsers sniff the content and render it correctly, which is precisely why these mismatches survive unnoticed for years. Everywhere else, yes. Image processing pipelines, CDNs that transform by type, PDF generators and mail clients read the declared type and act on it, and a wrong one gives you a corrupt output or a hard failure. This tool always writes the type the bytes actually are, and tells you when that differs from what the file name implied.

How large an image can I inline?

Technically very large — browsers impose no practical data URI limit for <img>. Practically, 4 KB is where inlining stops being obviously worthwhile and 100 KB is where it turns actively harmful, because the URI is re-downloaded with every change to the HTML or CSS carrying it and can never be cached on its own. This tool caps the source file at 8 MB, which is already far beyond anything that belongs inline; past that the string becomes unusable in the page and on the clipboard long before the encoding would fail.

Does this compress the image, and can I get the original back exactly?

It does not compress or resize anything, deliberately — the URI carries your bytes unchanged, which is what makes the round trip byte-exact. Decode a URI and the saved file is identical to the one that was encoded; hash both with the hash generator and the digests match. If the size warnings say the image is too heavy to inline, compress it with the image compressor first and encode the result, because encoding a 2 MB photo does not make a 2 MB photo any less of a problem.