What is Image to Base64 Converter?
This converter works in both directions: encode an image to Base64, or decode Base64 back to an image. To encode, drop an image onto the upload area or click to choose one; PNG, JPG, GIF, WebP, SVG and other browser-supported formats all work. You get a data URI, such as data:image/png;base64,iVBORw0KGgo…, that you can paste straight into the src of an img tag, a CSS background-image, a JSON payload or an email template, with no separate file to host.
To decode Base64 to an image, switch to Base64 to Image and paste a Base64 string or a full data URI. It works as a Base64 image decoder and viewer: the image is rendered immediately, so you can see what an API, a database field or a CSS file actually contains.
How to use Image to Base64 Converter
- Choose Image to Base64, or Base64 to Image.
- To encode, drag an image onto the upload area or click to browse; the data URI appears, ready to copy.
- To decode, paste a Base64 string or a full data URI; the image preview appears below.
- Copy the data URI into your HTML, CSS or JSON.
Key features
- Image to Base64 data URI and Base64 to image preview
- Drag and drop or click to upload
- PNG, JPG, GIF, WebP, SVG and other browser formats
- Data URI includes the correct MIME type
- One-click copy
- Images never leave your browser
Common use cases
- Inlining small icons and logos in HTML or CSS
- Embedding images in HTML email templates
- Sending images in JSON API requests that expect Base64
- Previewing Base64 images returned by APIs or stored in databases
- Creating self-contained single-file HTML demos
Technical details & standards
Encoding reads the file locally with the FileReader API and produces a data URI that includes the image's MIME type (RFC 2397). Base64 makes the data about 33% larger than the file, and a data URI cannot be cached separately from the page that contains it.
That makes inlining worthwhile mainly for small images, such as icons, logos and placeholders under a few kilobytes, where saving an HTTP request outweighs the size increase. For larger images, a normal file with caching and responsive srcset is faster. When previewing Base64 without a data: prefix, the data is shown as a PNG; include the full data URI for other formats.
Base64 encode an image in JavaScript, Python and the terminal
When you need image to Base64 inside a build script or app rather than in the browser, these produce the same data URI as the converter. The sample file is a 1 × 1 PNG.
JavaScript (Node.js)
const fs = require("fs");
const uri = "data:image/png;base64," + fs.readFileSync("dot.png").toString("base64");
// "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA…"Python
import base64
with open("dot.png", "rb") as f:
uri = "data:image/png;base64," + base64.b64encode(f.read()).decode("ascii")
# Decode a Base64 image back to a file
with open("copy.png", "wb") as f:
f.write(base64.b64decode(uri.split(",", 1)[1]))Terminal (macOS and Linux)
base64 -i dot.png # macOS
base64 -w 0 dot.png # Linux, on one line
base64 -d image.txt > out.png # decode back to a fileFrequently asked questions
How do I use a Base64 image in HTML?
Encode the image with Image to Base64, then put the data URI in the img tag's src attribute: <img src="data:image/png;base64,…" alt="…">. In CSS use background-image: url("data:image/png;base64,…");.
Does Base64 make images load faster?
Only for very small images, where avoiding an extra request matters more than the 33% size increase. Larger images load faster as normal cached files.
How do I convert Base64 back to an image file?
Switch to Base64 to Image and paste the string or data URI to decode it; the image appears in the preview. Right-click the preview and save it, or use File to Base64 in decode mode to download it with the correct extension.
Should I Base64-encode SVG images?
Often not: SVG is text, so it can be inlined directly in HTML or used as a URL-encoded data URI (data:image/svg+xml,…), which is usually smaller than Base64.
What does a Base64 PNG look like?
Every PNG encoded as Base64 starts with iVBORw0KGgo, which is the PNG signature. A complete 1 × 1 pixel PNG is data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==; paste it into the Base64 to Image mode to see it. JPEGs start with /9j/ and GIFs with R0lGOD.
Can I decode Base64 without the data:image prefix?
Yes. If the text does not start with data:image, the decoder adds data:image/png;base64, before previewing it. Browsers detect the real format from the bytes, so JPEG, GIF and WebP data still display, but keep the correct prefix when you use the string in your own HTML or CSS.
Can I resize an image while converting it to Base64?
No, the converter encodes the file exactly as it is. Resize or compress the image first, because Base64 makes it about 33% larger and every byte ends up inside your HTML or CSS.
Is my data safe?
Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.
Does it work offline?
Once the page has loaded, this tool can process input without an internet connection.