Image to Base64, and back to an image
Get a data URI of a PNG, JPG, SVG or WebP to paste into CSS, HTML, JSON or Markdown, made from the file’s own bytes. Or paste a Base64 string and see the picture it holds, then save it.
Or drop one anywhere on the page, or paste it with Ctrl+V. PNG, JPG, WebP, GIF, SVG, AVIF, ICO and BMP, up to 15 MB. The bytes are encoded as they are; nothing is re-saved.
Spaces, line breaks, quotes and URL-safe Base64 are fine. The picture type is read from the data itself, not from the text in front of it.
Encoded and decoded in this tab. Your images and text are never uploaded.
Three ways to use it
- 1
Pick, drop or paste a picture
A screenshot copied to the clipboard works too. The Base64 appears at once, with the original size, the text size and the picture’s width and height.
- 2
Copy the shape you need
A full data URI, the bare Base64, a ready CSS background-image line, an HTML img tag with width and height filled in, or a Markdown image. Each has its own Copy button.
- 3
Or go the other way
Switch to Base64 → Image, paste a string from an API response, a stylesheet or a log, and download the picture with the right extension.
When a data URI helps, and when it hurts
Putting a picture inside the code saves the browser one request for it, and keeps a page or a message in one piece. It also stops the picture from being cached on its own: every page that carries it downloads it again, and the browser cannot show the rest of the stylesheet or page until it has read through the text.
| Where | Worth it? | Why |
|---|---|---|
| A small icon or SVG in a stylesheet | Yes, under a few KB | One request fewer, and the icon arrives with the CSS that uses it, so it never pops in late. |
| A photo or hero image on a web page | No | A third bigger, cached only with the page, no lazy loading and no srcset for small screens. Serve the file. |
| An image field in a JSON API or a config file | Often | JSON has no binary type, so Base64 is the usual way in. For files of several MB, a multipart upload or a link is lighter. |
| HTML email | Rarely | Many webmail services and mail apps do not show data URI images at all. Attach the picture inline or link to a hosted copy. |
| A single-file HTML report, demo or test fixture | Yes | Everything travels in one file that opens offline, and a test does not depend on a path or a server. |
| A README or wiki page in Markdown | Depends | Some renderers strip data URIs for safety; a picture file committed next to the text works everywhere. |
How much bigger the text is
Base64 turns each group of 3 bytes into 4 characters, so the text is 4/3 the size of the file, rounded up to a multiple of four: 10 KB becomes about 13.3 KB, 100 KB about 133 KB and 1 MB about 1.33 MB. Base64 wrapped at 76 characters per line, as email uses, adds two more characters per line, roughly 2.6 % on top. Gzip and Brotli win most of the growth back in transfer, because Base64 only uses 64 different characters, but the browser still parses and decodes the full length.
Things that trip people up
- Content Security Policy. A site with a CSP needs
data:inimg-src(for HTML and CSS images) before data URI images will load. - Address bar. Modern browsers refuse to open a
data:URL as a page of its own when a link points to one, to stop phishing pages hidden inside them. Use it as an image source instead. - SVG. For a small SVG, URL-encoding (
data:image/svg+xml,%3Csvg…) is often shorter than Base64 and stays readable. The decoder above reads both kinds. - The wrong MIME type. A data URI that says image/png but holds a JPEG usually still shows, but some tools refuse it. The decoder reads the real type from the first bytes and tells you when the label is wrong.
Strings from your code stay in your tab
Base64 you paste here often comes from somewhere private: an API response, a database export, a customer’s upload in a log. The text is read and decoded inside this browser tab. Neither the text, nor the picture, nor the file name is sent to us or to any other service, and the page keeps nothing once you close it.
Questions & answers
Why is the Base64 text bigger than my image?
Base64 writes every 3 bytes of the file as 4 letters, so the text is always about 33 % longer: a 30 KB icon becomes 40 KB of text, a 3 MB photo 4 MB. The data URI adds a short prefix such as data:image/png;base64, on top. Served with gzip or Brotli, most of that growth disappears again in transfer, but the browser still has to read and decode the full text.
Is my image re-compressed or changed?
No. The page encodes the bytes of the file exactly as they are on your disk, so decoding the text gives back an identical file. That also means everything inside the file stays: a photo from a phone keeps its EXIF data, which can include where it was taken. To publish one, run it through Resize or Compress first; those save a new copy of the picture, and the original’s camera data and location are not written into it.
What is the largest image this page can handle?
15 MB for encoding, which makes about 20 MB of text, and the same amount the other way. Larger texts can freeze a phone’s browser when they are copied or pasted. Long results are shown as the first and last few hundred characters; Copy and Save .txt always take the whole text. In practice, anything over a few hundred kilobytes is better served as a normal image file.
Why does my Base64 not decode?
The usual causes are a copy that was cut off (the length is not a multiple of four, or the padding at the end is wrong), text that was URL-encoded on the way (%2B instead of +, %2F instead of /), or a stray character such as an ellipsis added by an editor. The page names the first character it cannot read and its position, so you can find it. Line breaks, spaces, surrounding quotes and the URL-safe alphabet are all accepted.
Is it safe to decode an SVG from someone else?
On this page, yes: the decoded picture is only ever shown as an image, and browsers never run scripts inside an SVG that is displayed that way. An SVG file is also a document, though. If you save one from an unknown source and open it directly in a browser tab, any script inside it can run there, so open untrusted SVG files in an image viewer or editor instead.
Make the image small before you encode it
The text can only be as small as the file. For an icon, crop it tight and save it at the size it is shown, a 64 × 64 PNG rather than the 1024-pixel original. For a photo, a WebP or a JPEG at quality 75 is often a tenth of the size of a PNG. Resize and Compress do both in this browser; bring the result back here. For a favicon, PNG to ICO makes the .ico file itself.