Base64 to image

Turn Base64 or a data URI into an image: how to tell the format by the first characters, and why a decode fails.

loading Base64 to image
About this tool

Base64 to image: what the decoder does

A Base64 string is the bytes of a file written as text. To get the picture back, the tool decodes the characters to bytes, finds out the image type and shows it, with a download button. You can paste a full data URI (data:image/png;base64,...) or only the part after the comma; without the prefix the type is recognised from the first bytes. Everything runs in your browser, so a private image is never sent anywhere. This page opens the tool in the Base64 to image direction, with a sample already decoded.

Worked example

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMjAiIGhlaWdodD0iNjAiIHJ4PSI4IiBmaWxsPSIjMWMyNDMwIi8+PGNpcmNsZSBjeD0iMzAiIGN5PSIzMCIgcj0iMTgiIGZpbGw9IiNmMmI4NGUiLz48L3N2Zz4=

Decoded, this is an image of type image/svg+xml with 170 bytes. For an SVG the bytes are readable text:

<svg xmlns="http://www.w3.org/2000/svg" width="120" height="60"><rect width="120" height="60" rx="8" fill="#1c2430"/><circle cx="30" cy="30" r="18" fill="#f2b84e"/></svg>

Pasting only the part after the comma gives the same result, with the type recognised from the content: image/svg+xml.

Tell the format by the first characters

Every file format starts with a fixed signature, so its Base64 starts the same way. Computed from the real signatures:

FormatBase64 starts withFirst bytes (hex)
PNGiVBORw0KGgo89 50 4e 47
JPEG/9j/ff d8 ff e0
GIFR0lG47 49 46 38
WebPUklGR52 49 46 46
SVGPHN2Zy3c 73 76 67
PDFJVBERi025 50 44 46

Why decoding fails

  • The text is cut: a copy that lost its end gives a broken image or no image. Base64 length is a multiple of 4 (with = padding at the end).
  • It is not an image: the decoded bytes may be a PDF, a ZIP or text. The tool tells you that the content is not an image instead of showing a blank box.
  • Line breaks and spaces inside the text are fine, but characters such as "-" and "_" mean URL-safe Base64, which uses another alphabet than the standard "+" and "/".

How to use the decoder

  1. Paste the Base64 or the data URI in the box; a sample is already there.
  2. Check the preview, the type and the size of the image.
  3. Download it with the right extension (png, jpg, svg…).

Frequently asked questions

How do I convert Base64 to an image file?

Paste the Base64 (or the whole data URI) in the decoder and press download: the file gets the extension that matches its real type.

Does the Base64 need the data:image prefix?

No. With the prefix the type is read from it; without it the decoder looks at the first bytes (PNG, JPEG, GIF, WebP, BMP and SVG are recognised).

Is it safe to paste a private image here?

Yes: decoding runs in your browser and nothing is sent to a server. Be careful with SVGs from unknown sources, which can contain scripts: the preview shows the picture as an image, where scripts do not run.

Report a problem