Encode images to Base64 and decode them back
Base64 is a way of representing binary data — like an image — using only plain text characters. Encoding an image to Base64 lets you embed the picture directly inside a text file such as a stylesheet, an HTML document, or a JSON payload, instead of linking to a separate image file. The encoded output is usually wrapped in a data URI, a string that begins with data:image/png;base64, followed by the encoded bytes, which browsers understand as an inline image anywhere a URL is expected.
This tool works in both directions. On the encode side, you upload an image and Pixohub produces the full Base64 data URI, ready to copy into your code. On the decode side, you paste a Base64 string or a complete data URI, and the tool reconstructs the original image so you can preview it and download it as a proper file. That makes it easy to inspect an inline image you found in some CSS, or to recover a picture that was stored as a string in a database or API response.
All of the work happens locally in your browser. Your images and strings are never sent to a server, so even large or sensitive files are handled privately and instantly. There is no signup, no watermark, and no limit on how many conversions you run.
How to use Base64 Image Encoder & Decoder, step by step
- Leave the switch on Encode and drop an image onto Drop an image. The file is read as it is, without re-encoding.
- The full data URI appears under Base64 data URI, with its length in characters next to the label. Check that length before pasting it into CSS or HTML.
- Press Copy Base64 to copy the whole string, including the data:image/…;base64, prefix.
- To go the other way, switch to Decode and paste a data URI or raw Base64 text into Paste a data URI or raw Base64 string.
- Press Decode to image. If the preview shows an error instead of a picture, the text is cut off or is not an image.
- Press Download image to save the decoded file.
Real example: encoding a PNG and round-tripping a JPG
We encoded Kodak test image 7, a 566,322-byte PNG. The data URI was 755,118 characters: 1.33 times the file size, plus a 22-character data:image/png;base64, prefix. Encoding took about 0.1 seconds.
Then we encoded our 425,116-byte test JPG (566,847 characters), switched to Decode, pasted the string and downloaded the result. The downloaded file had exactly the same bytes as the original JPG (identical MD5 checksum), so nothing was recompressed in either direction.
| File | Bytes | Data URI length |
|---|---|---|
| Kodak image 7, PNG | 566,322 | 755,118 characters |
| Test photo, JPG | 425,116 | 566,847 characters |
| JPG after decode | 425,116 (identical) | — |
Last updated
Base64 Image Encoder & Decoder compared with other ways to do it
Terminal commands
On macOS and Linux the base64 command encodes a file, and on Windows certutil -encode or PowerShell can do it. They are the best choice in scripts and build steps. They output raw Base64 only, so you add the data:image/…;base64, prefix yourself; this tool adds it with the correct type.
Build tools and bundlers
Web bundlers can inline small images automatically below a size limit you set, which is the better option inside a project that already uses one. This page is for one-off work: an email template, a single HTML file, a JSON fixture or checking what an inline string actually contains.
Upload-based Base64 converters
Online converters do the same encoding but send your image, or the pasted text, to a server first. For screenshots or documents that is worth avoiding. Here the file is read and the string decoded by your browser, and the decoded bytes in our test matched the original exactly.
When to inline images with Base64
Embedding an image as Base64 has real advantages in the right situation. Because the image travels inside the HTML or CSS itself, the browser does not need to make a separate network request to fetch it, which can eliminate a round trip for small, critical assets like an icon or a background pattern. It also makes a snippet fully self-contained: a single HTML file with inline images works with no external dependencies, which is handy for email templates, embedded documentation, or offline demos.
There is a trade-off to keep in mind. Base64 encoding increases the data size by roughly a third compared to the raw binary, and inlined images cannot be cached separately by the browser the way a linked file can. For that reason, inlining is best reserved for small images that appear on nearly every page. Large photos are almost always better served as normal linked files so they can be cached and loaded lazily.
As a practical rule, reach for Base64 when the asset is tiny and ubiquitous, or when you specifically need a self-contained file with no external requests. For everything else, a regular image URL is usually the better choice. This tool makes it easy to experiment either way — encode a candidate image, drop the data URI into your code, and see how it feels before committing.