Base64 to Image

Paste Base64 or a data URI, see the image, check its real format and size, and download it.

0 characters
Image
Preview background

Transparent areas and white-on-transparent icons only show up against the right background.

How to use

  1. Paste the Base64 string, or the whole data:image/…;base64,… URI, into the left box. An <img> tag or a CSS url() wrapped around it is fine too.
  2. The image appears on the right with its real format, pixel size and byte size. The line under it says anything that had to be cleaned up first.
  3. Switch the Preview background to Light or Dark if the image has transparent or white areas.
  4. Download image saves it with the right extension; Copy data URI gives you a clean data: string for HTML or CSS.

What this decoder does that a text decoder cannot

A Base64 string that came from an image decodes to binary, not text, so a general Base64 decoder stops with “not valid UTF-8”. This page decodes the same string to bytes, reads the file signature to find out which of eight image formats it is, reads the pixel size from the header, and hands the bytes to your browser's own image decoder for the preview. The download is the original file, byte for byte, named with the extension the bytes call for.

Before decoding it repairs the ways these strings get mangled in transit: a data: prefix, the <img src="…"> or url(…) it was copied out of, JSON quotes and \/ escapes, line breaks added by an email client, percent-encoding from a query string, the URL-safe alphabet, and missing = padding. Each repair is listed under the preview so you can see why another tool rejected the same input. It does not resize, convert or optimise the image; the bytes out are the bytes in.

Example

Load sample inserts this 157 B PNG as a data URI:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAZElEQVR42mNgQAOqya//0xIz4AK0thivQ+htOYYjBtQBA2U53BGjDhiSDsAFaO4AYgFNHEAqoKoDyAXDwwGUglEHjDpg6DtgtBwYFEXxoKiMBkV1PNoiGp4OGO0ZDYrO6UB2zwEFpbp3WQ7rpgAAAABJRU5ErkJggg==

The page decodes it and reports PNG · 32 × 32 px · 157 B, shows a blue square with a white dot, and enables Download image (saved as image.png). The status line reads “Cleaned up before decoding: removed the data: prefix.” Pasting only the part after the comma gives the same result with no status line.

Options explained

Edge cases and common errors

Do the same thing in code

HTML and CSS

<img src="data:image/png;base64,iVBORw0KGgo…" alt="" width="32" height="32">

.icon { background-image: url("data:image/png;base64,iVBORw0KGgo…"); }

JavaScript

// Browser: bytes for a Blob or a download
const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
const blob = new Blob([bytes], { type: "image/png" });

// Node.js: write the file
import { writeFile } from "node:fs/promises";
await writeFile("image.png", Buffer.from(base64, "base64"));

Python

import base64
with open("image.png", "wb") as f:
    f.write(base64.b64decode(data))   # data = the part after the comma

Shell

echo 'iVBORw0KGgo…' | base64 -d > image.png    # Linux
echo 'iVBORw0KGgo…' | base64 -D > image.png    # macOS

To go the other way (a file into a data URI), use Image to Base64. If the Base64 came out of a JWT, the JWT decoder splits and decodes all three segments at once; if it was pasted from a URL, the URL decoder shows the un-escaped form.

Base64 to Image FAQ

Why does my Base64 image show as broken?

Usually one of three things: the string was cut short (a database column limit or a chat window truncating it), the data: prefix names the wrong type (image/jpeg in front of PNG bytes), or the text was URL-encoded or JSON-escaped and never decoded. This page reports each case separately: a truncated file is flagged from its missing end-of-file marker, a wrong prefix is corrected from the bytes, and escapes are undone before decoding.

Do I need the data:image/png;base64, prefix?

No. The format is read from the first bytes of the decoded data, not from the prefix, so a bare Base64 string works. If a prefix is present it is stripped, and if it disagrees with the bytes the page tells you and the download uses the real type. The Copy data URI button always builds the prefix from the detected type.

How do I know what image format a Base64 string is?

Decode it here and read the line under the preview: PNG, JPEG, GIF, WebP, SVG, BMP, ICO or AVIF, taken from the file signature. As a shortcut, PNG Base64 starts with iVBOR, JPEG with /9j/, GIF with R0lGOD, WebP with UklGR and SVG with PHN2Zy or PD94bWw: those are the first bytes of each format encoded.

Can I decode a Base64 PDF or other file here?

The preview only renders images, but the Base64 is still decoded. If the bytes turn out to be a PDF, a ZIP or something the page cannot identify, a Download as file anyway button appears and saves them with the matching extension (.pdf, .zip, or .bin). Plain text is handed to the Base64 text decoder instead.

Is the image uploaded anywhere?

No. This page is a static file with no server behind it; decoding runs in your browser with the standard atob() function and the preview is an element pointing at a data URI held in memory. Closing the tab discards it. Nothing you paste is sent or stored.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta. Implements RFC 2397 (data: URLs).