Skip to content
ToolShedby Wasim Shaikh

Base64 to Image Converter

Paste a Base64 string or data URI to preview the image, check its real format and size, and download it. Runs in your browser.

Have an image instead? Image to Base64 turns any image into a Base64 string.

How to Convert Base64 to an Image

  1. Paste the string. Paste raw Base64 or a full data URI, or drop a .txt file on the box. Quotes, line breaks and CSS url() wrappers are removed for you.
  2. Check the result. The format is detected from the data itself, with the dimensions and file size. Errors say exactly what is wrong.
  3. Download or copy. Download the image with the right file extension, or copy it to the clipboard to paste somewhere else.

Recognise the Format From the First Characters

Every image format starts with a fixed byte pattern, so its Base64 starts with fixed characters too. That is how this tool, and the WHATWG MIME sniffing rules that browsers follow, tell formats apart without a file name.

FormatBase64 starts withFirst bytes
PNGiVBORw0KGgo89 50 4E 47
JPEG/9j/FF D8 FF
GIFR0lGOD47 49 46 38 ("GIF8")
WebPUklGR52 49 46 46 ("RIFF") … "WEBP"
SVGPHN2Zy or PD94bWwg"<svg" or "<?xml"
ICOAAABAA00 00 01 00
BMPQk42 4D ("BM")

Fixing Base64 That Will Not Decode

"Invalid character" error
Something other than Base64 was copied, often a stray quote, comma or HTML. The error gives the position so you can find it.
"Cut off" or wrong-length error
The string was truncated, which is common when copying from logs or a debugger that shortens long values. Copy the full value again.
Decodes to text, not an image
The Base64 is valid but holds text or JSON. Open it in the Base64 Decoder instead.
Type mismatch warning
The data URI says one type (say image/png) but the data is another (say JPEG). Fix the prefix, or browsers and email clients may refuse it.
Strings with - and _
That is base64url, used in URLs and JWTs. It is converted to standard Base64 automatically.

Decode a Base64 Image in Code

JavaScript (browser)

const res = await fetch(dataUri); // "data:image/png;base64,..."
const blob = await res.blob();
img.src = URL.createObjectURL(blob);

Python

import base64
data = base64.b64decode(encoded)
with open("image.png", "wb") as f:
    f.write(data)

Frequently Asked Questions

Is the Base64 sent to a server?
No. Decoding happens in your browser with JavaScript, and the preview and download are made on your device. That makes it safe for images from private APIs and test data.
How does the tool know the image format?
It reads the first bytes of the decoded data, the "magic bytes" every format starts with, instead of trusting the data URI prefix. So a raw string with no prefix still downloads with the right extension, and a wrong prefix is flagged.
Do I need the data:image/png;base64, prefix?
No. Paste either the full data URI or only the Base64 part. Wrappers like quotes, src= and CSS url() are removed automatically, as are spaces, line breaks and JSON \n escapes.
Why does my Base64 string not show an image?
Usually the string was cut off when copied, has extra characters in it, or is not an image at all. The message under the box says which. If the bytes look like text, the tool links to the text Base64 Decoder.
Can I convert Base64 to PNG or JPG?
The download keeps the format the data is already in, so a JPEG downloads as .jpg and a PNG as .png, with no quality loss. Copy image always puts a PNG on the clipboard, which most apps accept.
Is it safe to preview an SVG from an unknown source?
Yes. SVG previews are shown with an img element, and browsers never run scripts inside an SVG loaded that way.
How do I turn an image into Base64?
Use the Image to Base64 converter. It gives you the data URI, an img tag, a CSS background, Markdown or JSON, for one image or up to 20 at once.

Sources & Standards

Decoding and format detection follow the standards below. Last reviewed .

Going the other way? Image to Base64 encodes images. For Base64 that holds text, use the Base64 Decoder.

Related Tools