B6
100% Client-SideAbout
Back to tool
Guide5 min read

Base64 to Image

How to decode a Base64 string back into a viewable image — online, in JavaScript, Node.js, and Python.

Have a Base64 string to decode?

Paste it into the free online tool — see the image preview instantly, no upload.

Decode Now

What is a Base64 image (data URI)?

A Base64 image is an image file whose binary data has been encoded into a plain-text string. It's often packaged as a data URI — a string that starts with data:image/png;base64, (or jpeg, svg+xml, etc.) followed by the Base64-encoded image bytes.

Data URIs let you embed images directly inside HTML, CSS, and JSON without separate file requests. But when you need to recover the actual image file — to view it, resize it, or save it — you need to decode the Base64 string back to binary.

Decoding is the exact reverse of encoding: the Base64 alphabet maps back to 6-bit groups, which are reassembled into the original bytes. The result is an identical copy of the original image file.

Decode Base64 to image online — step by step

01

Open the Base64 Image decoder

Go to Base64 Tool and click the Image tab. No sign-up needed — everything runs in your browser.

02

Switch to Decode mode

Inside the Image tab, click the Decode toggle. The interface switches to show a text area for pasting your Base64 string.

03

Paste your Base64 data URI

Paste the full Base64 data URI (e.g. data:image/png;base64,iVBORw0KGgo...) into the text area. The tool auto-detects the MIME type from the data: prefix and renders a live image preview immediately.

04

Preview and download

The decoded image appears below the text area. Click Download to save it as a file. The filename is automatically inferred from the MIME type (e.g. image.png).

Decode Base64 to image in code

Decode a Base64 data URI to an image in the browser (JavaScript)

A Base64 data URI can be used directly as an image src — no decoding step needed in most browser contexts:

// Option 1: Use the data URI directly as an image src
const dataUri = "data:image/png;base64,iVBORw0KGgo...";
const img = document.createElement("img");
img.src = dataUri;
document.body.appendChild(img);

// Option 2: Convert to a Blob, then create an object URL
function dataUriToBlob(dataUri) {
  const [header, base64] = dataUri.split(",");
  const mimeType = header.match(/:(.*?);/)[1];
  const binary = atob(base64);
  const bytes = new Uint8Array(binary.length);
  for (let i = 0; i < binary.length; i++) {
    bytes[i] = binary.charCodeAt(i);
  }
  return new Blob([bytes], { type: mimeType });
}

const blob = dataUriToBlob(dataUri);
const objectUrl = URL.createObjectURL(blob);
img.src = objectUrl; // use like a regular URL

Download a decoded image in the browser

Trigger a file download from a Base64 data URI using a hidden anchor element:

function downloadBase64Image(dataUri, filename = "image.png") {
  const link = document.createElement("a");
  link.href = dataUri;
  link.download = filename;
  link.click();
}

downloadBase64Image("data:image/jpeg;base64,/9j/4AAQ...", "photo.jpg");

Decode Base64 to an image file in Node.js

Use Node.js Buffer to decode a Base64 string and write it back as a binary image file:

const fs = require("fs");

// The Base64 string (without the data URI prefix)
const base64String = "iVBORw0KGgo...";

// Decode and write to file
const buffer = Buffer.from(base64String, "base64");
fs.writeFileSync("output.png", buffer);
console.log("Image saved to output.png");

// If you have the full data URI, strip the prefix first:
function saveDataUri(dataUri, outputPath) {
  const base64 = dataUri.replace(/^data:image\/\w+;base64,/, "");
  fs.writeFileSync(outputPath, Buffer.from(base64, "base64"));
}

Decode Base64 to an image in Python

Python's base64 module decodes the string; then write the bytes to a file:

import base64

# Decode and save as image file
base64_string = "iVBORw0KGgo..."  # without the data URI prefix
image_bytes = base64.b64decode(base64_string)

with open("output.png", "wb") as f:
    f.write(image_bytes)

# If you have the full data URI:
def save_data_uri(data_uri, output_path):
    base64_part = data_uri.split(",", 1)[1]
    with open(output_path, "wb") as f:
        f.write(base64.b64decode(base64_part))

When do you need to decode Base64 to an image?

Recovering embedded images from HTML or CSS

If you have HTML with inline data URIs (from email templates, legacy code, or scraped pages) and need to extract them as actual image files, decode each data URI back to a file.

Inspecting API responses that return image data

Some APIs return images as Base64 strings in JSON payloads (e.g., generated QR codes, thumbnail previews, or profile photos). Decode them to preview or save the result.

Debugging image encoding pipelines

If your Base64 encode/upload/decode pipeline produces corrupted images, decode the Base64 output at each stage to visually verify the data is intact.

Converting Base64 screenshots from test runners

Playwright, Puppeteer, and Selenium can return screenshots as Base64 strings. Decode them to PNG files for inspection.

Your data stays private

All decoding happens in your browser — your Base64 strings and the resulting images are never uploaded to any server. This makes the tool safe for private or sensitive image data.

Ready to decode your Base64 image?

Free, instant, and 100% private — nothing is ever uploaded to a server.

Open Image Decoder