Base64 to Image Converter

Paste a Base64 image, with or without the data:image/…;base64, prefix, and see it straight away. The file type is read from the decoded bytes, not guessed from the prefix, so you also find out when a “PNG” is really a JPEG. Download the result with the right extension. Decoding happens in your browser.

The image appears here

How to convert Base64 to an image

  1. Paste the Base64 text into the box. Any of these forms work:
    • a full data URI: data:image/png;base64,iVBORw0KGgo…
    • raw Base64 with no prefix: iVBORw0KGgo…
    • text copied from CSS or HTML, such as url("data:image/svg+xml;base64,…") or src="data:…"
    • a JSON string value with quotes and escaped slashes (\/)
    • Base64 wrapped onto many lines, as email attachments and PEM-style dumps are
    • URL-safe Base64 (Base64URL), which uses - and _ instead of + and / and often drops the = padding
  2. The image appears as soon as you paste. The panel on the right shows the detected format, pixel dimensions, file size and the size of the Base64 text.
  3. Click Download to save the file. The extension comes from the detected format, so a JPEG is saved as .jpg even if the data URI said image/png.

How the file type is detected

The data:image/png part of a data URI is only a label, and it is often wrong: code that builds data URIs commonly hard-codes image/png for every image. Most file formats instead start with a fixed signature, called magic bytes, and this tool reads those after decoding:

FormatFirst bytes (hex)Base64 starts with
PNG89 50 4E 47 0D 0A 1A 0AiVBORw0KGgo
JPEGFF D8 FF/9j/
GIF47 49 46 38 37/39 61 (“GIF87a” / “GIF89a”)R0lGOD
WebP52 49 46 46 … 57 45 42 50 (“RIFF” … “WEBP”)UklGR
BMP42 4D (“BM”)Qk
ICO00 00 01 00AAABAA
PDF25 50 44 46 2D (“%PDF-”)JVBERi0
SVGtext: <svg, or <?xml followed by an <svg elementPHN2Zy or PD94bWwg
AVIFftypavif at byte 4AAAA, then usually …GZ0eXBhdmlm
TIFF49 49 2A 00 or 4D 4D 00 2ASUkqAA or TU0AKg

The “Base64 starts with” column is handy for spotting an image type by eye in a log file or database dump. If the declared and detected types differ, the tool shows a warning and uses the detected type for the preview and the download.

Pixel dimensions are read from the file header as well (the PNG IHDR chunk, the GIF screen descriptor, the JPEG start-of-frame marker, the WebP VP8/VP8L/VP8X chunk, the BMP info header, the ICO directory and the SVG width, height or viewBox), so you get them even for formats your browser cannot display.

Errors and what they mean

“Invalid Base64 character”

Base64 only contains A–Z, a–z, 0–9, +, / and = padding (or - and _ in the URL-safe variant). The error gives the position of the first character that does not belong. A common cause is copying a percent-encoded data URI, where + became %2B and / became %2F; the tool decodes those automatically, but other escaping such as \u002B has to be removed first.

“Length is not valid Base64”

Every four Base64 characters encode three bytes. After padding is removed the length can leave a remainder of 0, 2 or 3 characters when divided by 4, but never 1. A remainder of 1 means at least one character is missing, usually because the string was cut off.

“The data looks truncated”

The bytes start like a valid image but the end marker is missing: a PNG without its final IEND chunk, a JPEG without the FF D9 end-of-image marker, or a GIF without the 3B trailer. Browsers often still show the top part of the picture, with the rest grey or missing. This happens when text is cut at a database column limit, a log line limit or a clipboard limit. Get the full value from the source.

“Unknown format”

The bytes decoded correctly but do not match any image signature. The first bytes are shown in hex so you can identify the file: 50 4B 03 04 is a ZIP (also DOCX and XLSX), 1F 8B is gzip, and 7B is the { that starts a JSON document. The data may also be encrypted or Base64-encoded twice; if it starts with Base64 characters again, decode it a second time.

The preview is blank but there is no error

Some formats are valid but not supported by every browser. TIFF only displays in Safari, and AVIF needs a recent browser. The download still gives you the correct file.

Base64 size overhead

Base64 represents every 3 bytes with 4 characters, so encoded data is about 33% larger than the file (plus a few characters of padding and the prefix). A 30 KB image becomes roughly 40 KB of Base64 text. That is why inlining images as data URIs only makes sense for small images such as icons: large ones bloat HTML and CSS and cannot be cached separately by the browser.

Decode Base64 to an image file in code

Python:

import base64, re

data = open("image.txt").read().strip()
data = re.sub(r"^data:[^,]*,", "", data)          # drop a data URI prefix
data += "=" * (-len(data) % 4)                    # restore missing padding
with open("image.png", "wb") as f:
    f.write(base64.b64decode(data))

Node.js:

const fs = require("fs");
const b64 = fs.readFileSync("image.txt", "utf8").replace(/^data:[^,]*,/, "").trim();
fs.writeFileSync("image.png", Buffer.from(b64, "base64"));

In the browser, await (await fetch(dataUri)).blob() turns a data URI into a Blob you can download or upload. On macOS and Linux, base64 -d image.txt > image.png works when the file holds raw Base64 without the prefix (use base64 -D on older macOS).

Privacy and safety

The Base64 text is decoded with JavaScript in this page and shown through a local blob URL; nothing is uploaded. SVG files can contain scripts, but an SVG displayed through an <img> element cannot run them, which is how this page previews SVG. PDFs are shown in the browser’s built-in PDF viewer.

To go the other way and turn a picture into Base64, use the image to Base64 converter.

Frequently asked questions

How do I convert a Base64 string to an image?

Paste the Base64 text into the box on this page. The image is decoded and displayed immediately, and the Download button saves it as a file with the correct extension. The prefix data:image/…;base64, is optional.

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

No. Raw Base64 works too. The tool detects the format from the decoded bytes, so it knows whether the data is a PNG, JPEG, GIF, WebP, SVG, BMP, ICO or PDF without the prefix.

How can I tell the image type from a Base64 string?

Look at the first characters. iVBORw0KGgo is PNG, /9j/ is JPEG, R0lGOD is GIF, UklGR is a RIFF file such as WebP, PHN2Zy is SVG and JVBERi0 is PDF.

Why is my Base64 image broken or only partly shown?

Usually the string was cut off, for example by a database column or log line limit. The tool warns when the end-of-file marker is missing. Invalid characters or a length that leaves a remainder of 1 when divided by 4 also mean the data is damaged.

Can I convert Base64 to JPG or PNG?

The download keeps the original format, because converting would re-encode the image. To change the format, download it and use the image converter.

Is there a size limit?

There is no fixed limit; the decode runs in your browser’s memory. Base64 strings of tens of megabytes work in modern desktop browsers but can be slow on phones.

Is the image uploaded to a server?

No. Decoding and preview happen entirely in your browser, so it is safe to use with private screenshots or customer documents.