Base64 to Image Converter
Switch to Image to Base64A Base64 to image converter decodes a text string back into the original image file's bytes, so you can see the picture and save it as a normal PNG, JPG, GIF, WebP or SVG file. Paste raw Base64 or a full data:image Data URI below to preview it, check its real format and size, and download it.
1 Paste Base64
To decode PDFs, text and any other file type, use the Base64 encoder / decoder instead.
Accepts raw, URL-safe and Data URI Base64. Spaces, line breaks, quotes, a CSS url() wrapper and JSON \/ escapes are cleaned up automatically. Decoding happens in your browser; nothing is uploaded.
2 Image
How to convert Base64 to an image
-
1
Paste the Base64
Paste a raw Base64 string, a URL-safe string or a full data:image/...;base64, Data URI into the box. Line breaks, spaces, surrounding quotes and a CSS url() wrapper are all removed for you.
-
2
Let it detect the format
The tool decodes the string and identifies the format from the file's signature bytes: PNG, JPG, GIF, WebP, SVG, ICO or BMP. It ignores whatever the prefix claims.
-
3
Check the preview and details
The image appears with its format, pixel dimensions and decoded file size. A note lists anything that was fixed automatically, such as a missing prefix or padding.
-
4
Download the image
Press Download to save the image with the extension that matches its real format, ready to open in any image viewer or editor.
-
5
Copy a clean version if you need one
Use Copy Data URI for a complete, correctly prefixed value to put in HTML or CSS, or Copy raw Base64 for a standard, padded string an API will accept.
A worked example: 152 characters, one PNG
"Load example" pastes this string. It has no data: prefix, so nothing in it says it's an image:
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAN0lEQVR42mNgoAVgajn+HxumSDNRhhDSjNcQYjVjNYRUzRiGjBpABQMojkaqJCSqJGWqZCZSAQAFfWZgM5ZAWQAAAABJRU5ErkJggg==
The decoder turns the 152 characters into 112 bytes. The first eight bytes are 89 50 4E 47 0D 0A 1A 0A, the fixed signature every PNG file opens with, and that's what the opening iVBORw0KGgo encodes. The tool reports a 16×16 PNG of 112 bytes, shows a blue dot, and builds this Data URI for you:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAN0lEQVR42mNgoAVgajn+HxumSDNRhhDSjNcQYjVjNYRUzRiGjBpABQMojkaqJCSqJGWqZCZSAQAFfWZgM5ZAWQAAAABJRU5ErkJggg==
Where Base64 images come from
Most Base64 images reach you inside something else, and each source leaves its own marks on the string:
- API responses. Image-generation, screenshot, OCR and document APIs often return pictures as a Base64 field in JSON, sometimes with a separate
mime_typefield and no prefix. Copy just the value between the quotes. - Email source. In a raw message (the "Show original" or "View source" option in most mail clients), inline images and attachments are MIME parts marked
Content-Transfer-Encoding: base64, wrapped at 76 characters per line. Copy everything after the blank line under the part's headers, up to the next--boundary line. - JSON files and database fields. Avatars, signatures and thumbnails get stored in text columns or JSON documents. Exported JSON often escapes every slash as
\/, and database GUIs may truncate long values when you copy a cell. - CSS and HTML. Icons inlined in a stylesheet as
url("data:image/..."), or an<img>whosesrcis a Data URI. Paste the wholeurl(...)value; the wrapper is stripped for you. - Browser code.
canvas.toDataURL()andFileReader.readAsDataURL()both produce Data URIs, which end up in logs, local storage and form submissions.
Going the other way, from a file to a string you can embed, is a separate job: convert an image to Base64 with a matching tool that also writes the CSS and HTML snippets.
Common problems and fixes
Missing data: prefix
Raw Base64 in an src attribute gets treated as a relative URL and fails to load. Add data:image/png;base64, (with the right format) in front. This tool detects the format and builds the full Data URI for you.
Line breaks and spaces
Email bodies and PEM-style output wrap Base64 every 64 or 76 characters, and copying from a terminal or PDF can add spaces. They aren't part of the data. Strip all whitespace before decoding; the tool does it automatically.
URL-safe characters
Strings taken from URLs, JWTs or some cloud storage APIs use - and _ instead of + and /, and often drop the padding. A strict decoder rejects them, so swap the two characters back first. If the string came out of a query parameter, also watch for %2B, %2F and %3D.
Truncated strings
If the length leaves one stray character in the final group, the string was cut off and can't be decoded. If it decodes but the image is cut off or won't render, the end of the file is missing. PNG, JPEG and GIF files close with a fixed end-of-file marker, and the tool warns when that marker isn't there. Either way, copy the value again from its source. Exporting the field to a file avoids most copy-length limits.
Wrong padding
The = signs only pad the last group to a multiple of four characters: a valid string has none, one or two, and only at the very end. Missing or extra padding is fixed here automatically. An = in the middle usually means two values were pasted together.
It isn't actually an image
Valid Base64 can hold anything. If the decoded bytes have no image signature, the tool says what they look like instead (a PDF, a ZIP-based Office file or plain text). For those, the Base64 encoder / decoder decodes any file type and offers it as a download.
Code examples
HTML
A Data URI works anywhere an image URL does. Keep width and height so the page doesn't shift when the image decodes.
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAN0lEQVR42mNgoAVgajn+HxumSDNRhhDSjNcQYjVjNYRUzRiGjBpABQMojkaqJCSqJGWqZCZSAQAFfWZgM5ZAWQAAAABJRU5ErkJggg==" width="16" height="16" alt="Blue status dot">
To see a snippet like this render before it goes into a template, paste it into the HTML viewer and live renderer.
JavaScript: decode and download as a Blob
function downloadBase64Image(base64, mime, filename) {
const binary = atob(base64.replace(/\s+/g, ''));
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
const url = URL.createObjectURL(new Blob([bytes], { type: mime }));
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
downloadBase64Image(base64String, 'image/png', 'decoded.png');
PHP: decode, validate, save
Pass true as the second argument so invalid input returns false instead of silently skipping bad characters. If the string comes from a user, check the decoded bytes' real type before writing anything to disk: the data: prefix and the filename are both just claims. Allow only the formats you expect, generate the filename yourself, and leave SVG off the list unless you sanitize it, because SVG can carry scripts.
<?php
$base64 = preg_replace('/^data:[^,]*,/', '', $input); // drop any data: prefix
$bytes = base64_decode($base64, true);
if ($bytes === false) {
throw new InvalidArgumentException('Not valid Base64.');
}
$allowed = ['image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/webp' => 'webp'];
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($bytes); // from the bytes, not the prefix
if (! isset($allowed[$mime])) {
throw new InvalidArgumentException("Unsupported type: $mime");
}
file_put_contents(__DIR__ . '/uploads/' . bin2hex(random_bytes(8)) . '.' . $allowed[$mime], $bytes);
Supported formats and how to spot them
Every format starts with a fixed signature, so its Base64 always starts with the same characters. That gives you a quick way to identify a string at a glance:
| Format | Base64 starts with | Notes |
|---|---|---|
| PNG | iVBORw0KGgo | The most common format in API responses and inlined icons. Transparency is preserved, so the preview sits on a checkerboard. |
| JPG / JPEG | /9j/ | Photos and camera uploads. Downloads as .jpg. |
| GIF | R0lGOD | Animated GIFs play in the preview and download with every frame intact. |
| WebP | UklGR | A RIFF container, confirmed by the WEBP marker in bytes 8–11 rather than the first characters alone. |
| SVG | PHN2Zy or PD94bWwg | Text markup (<svg or <?xml), detected by its content. Previewed safely through <img>. |
| ICO | AAABAA | Favicons. One file can hold several sizes; the preview shows whichever one the browser picks. |
| BMP | Qk | Uncompressed and large for its dimensions. Common in older Windows systems and scanner output. |
For why every 3 bytes become exactly 4 characters, and why the decoded image is about a quarter smaller than the string, see Base64 encoding explained.
Frequently asked questions
Paste the string into the box above and press Download. The tool reads the first bytes of the decoded data to find the real format, so a PNG downloads as .png and a JPEG as .jpg, whatever the prefix claimed. It does not change the format itself: decoding a JPEG gives you a JPEG. To end up with a PNG from JPEG data, open the downloaded file in an image editor and export it.
In order of how often it happens: the string was cut off when copied (log viewers and database clients often truncate long values), the src is missing the data:image/...;base64, prefix, the value still contains JSON escapes such as \/ or literal \n, or the data is not an image at all. Paste it here and the tool tells you which one it is, fixing the escapes and prefix automatically.
Not to decode it here: raw Base64 works, and the tool adds the right prefix to the Data URI copy button from the detected format. You do need it anywhere a browser reads the value, such as an img src or a CSS url(), because the prefix is what tells the browser the text is image data and which format to decode.
Yes. The tool recognizes SVG from its markup and previews it like any other image. The preview loads it through an img element, where scripts inside the SVG never run. Treat a downloaded SVG from an unknown source with more care: opened directly in a browser tab, an SVG file can execute embedded JavaScript.
No. Decoding uses the browser's own atob function and the preview is a local blob: URL created on your device. The string, the decoded image and the downloaded file never reach a server, so it is safe for screenshots from support tickets or images pulled out of private API responses.
No. This page only handles images, and it will say when a string decodes to a PDF, ZIP or text instead. For any other file type, use the decode mode of Frost Rank's Base64 Encoder / Decoder, which accepts the same strings and downloads whatever file the bytes contain.
Look at the first few characters, because each format's file signature always encodes the same way: iVBORw0KGgo is PNG, /9j/ is JPEG, R0lGOD is GIF, UklGR is a RIFF container (WebP), PHN2Zy or PD94bWwg is SVG markup, AAABAA is ICO and Qk is BMP. The table above lists them.
Uses the same Base64 engine as Frost Rank's other Base64 tools, and identifies formats from the decoded file signatures. Every "starts with" prefix in the table above was produced by encoding the real signature bytes, not copied from a reference.
Was this tool helpful?
Rate it and leave a comment — takes 10 seconds, and genuinely helps decide what to fix or build next.