LocalFirstTools.com, data tools that never leave your device
No upload, everything runs on your device

Image to Base64 (and back)

An image file is bytes, and Base64 writes those bytes as text using 64 ASCII characters: 4 characters for every 3 bytes. Drop an image below to get its Base64 or a ready-to-paste data: URL, or switch to Base64 → File, paste Base64 and get the image back with a preview and a download, all inside this tab.

The size change is fixed arithmetic. 4 output characters per 3 input bytes makes the Base64 33.3% longer than the image before padding: a 30,000-byte PNG becomes exactly 40,000 characters, and the data: URL prefix adds a constant 22 characters for image/png (data:image/png;base64,) or 23 for image/jpeg. Going back, every 4 characters yield 3 bytes, and the file type is read from the first bytes: PNG starts 89 50 4E 47, JPEG FF D8 FF, GIF 47 49 46 38, and WebP has RIFF at byte 0 and WEBP at byte 8.

File
Base64
Converted on this deviceNothing leaves this tab

When it goes wrong

If Decode reports “That string is not valid Base64: its length mod 4 is 1, so at least one character is missing.”, the paste is incomplete (a Base64 string is always a multiple of 4 characters after padding), so copy the whole value again, including the data:image/…;base64, prefix if it has one. If the preview stays empty and the type reads “Unknown binary (application/octet-stream)”, the bytes are not one of the recognised image formats; Download still saves them as .bin, and renaming the extension will not fix a file that was never an image.

When to use this

Inline small icons and logos in HTML or CSS as data: URLs to save a request, embed an image in JSON or an email, or recover an image from a data: URL someone pasted. Above a few kilobytes a separate file the browser can cache is usually better: the +33.3% is paid on every page load.

This page is a focused view of theBase64 Encode / Decode: Text, Images & Files, which has the full set of options.

Frequently asked questions

Which image formats work?

Any file encodes. When decoding, the preview and the extension are automatic for PNG, JPEG, GIF, WebP, BMP, TIFF, ICO and SVG, detected from the first bytes or the data: URL prefix; other formats still download as a .bin you can rename.

How do I use the Base64 in an <img> tag?

Turn on Data URL and paste the result into src: <img src="data:image/png;base64,iVBORw0…">. The same string works in CSS as url(data:image/png;base64,…).

Is the image uploaded?

No. The browser's File API reads it into this tab's memory and the encoding runs there. No request carries it.