How to convert Base64 to an image
- Paste the string into the box. A long value saved in a file can be opened with Open .txt file or dropped onto the box.
- With Live on, the image decodes as you paste. The status line shows whether the Base64 is valid, the variant (standard or Base64URL), the byte count and the Detected format.
- Check the preview. Under it you see the type, MIME type, extension, size in bytes, pixel dimensions and the SHA-256 hash.
- Adjust File name if you like and press Download file. Copy as data URI gives you a clean
data:URI for HTML or CSS instead.
Sample loads a small PNG, so you can see how the output looks before pasting your own data.
What you can paste
The decoder is forgiving about the wrapper around the Base64, because image strings rarely arrive clean:
- Bare Base64, as an API returns it:
iVBORw0KGgoAAAANSUhEUg... - A data URI:
data:image/png;base64,iVBORw0KGgo... - Code that contains one:
background-image: url("data:image/svg+xml;base64,..."),<img src="data:image/jpeg;base64,...">, a Markdown image, or a JSON field whose value is a data URI. The first data URI is extracted for you. - Line-wrapped Base64 from email sources or PEM-style output, with spaces or line breaks every 64 or 76 characters.
- URL-safe Base64 with
-and_, strings without=padding, and values wrapped in quotes.
If the Base64 sits in a JSON field without a data: prefix, copy only the value between the quotes. A whole JSON document is rejected as invalid Base64, since { is not part of the alphabet.
How the format is detected
Every image format begins with a fixed signature, its magic bytes. The tool decodes the string and compares the first bytes against those signatures, so a string labelled image/png that really holds a JPEG is recognized as JPEG. The same signatures are visible in the Base64 itself, which helps when you read logs or database dumps:
| Format | First bytes | Base64 starts with | MIME type |
|---|---|---|---|
| PNG | 89 50 4E 47 0D 0A 1A 0A | iVBORw0KGgo | image/png |
| JPEG | FF D8 FF | /9j/ | image/jpeg |
| GIF | GIF89a / GIF87a | R0lGODlh / R0lGODdh | image/gif |
| WebP | RIFF, size, WEBP | UklGR, with XRUJQ at characters 12–16 | image/webp |
| SVG | <svg / <?xml | PHN2Zy / PD94bWwg | image/svg+xml |
| ICO | 00 00 01 00 | AAABAA | image/x-icon |
| BMP | BM | Qk | image/bmp |
| HEIC | size, ftypheic | AAAA, then eXBoZWlj at character 9 | image/heic |
| TIFF | II* / MM* | SUkqAA / TU0AKg | image/tiff |
AVIF, JPEG XL and cursor (.cur) files are detected too. When a data URI declares a type and the content says otherwise, a note shows both. If the data is not an image at all, for example a PDF, the page says so and offers a Download as .pdf button. The common Base64 prefixes page lists signatures for many more file types.
Why the image does not show
The string was cut off. Base64 values get truncated by log line limits, database column sizes, spreadsheet cells (32,767 characters) and copy-paste from terminals. A JPEG or PNG then renders only partly, or the preview fails. If one character too many or too few makes the length impossible, you get a “Wrong length” error. A valid but short string decodes without an error, so compare the Size with what you expected.
The MIME type in the data URI is wrong. data:image/png in front of JPEG bytes usually still displays in browsers, which sniff raster images, but other software trusts the label. SVG is never sniffed: with any type other than image/svg+xml it does not render in an <img>. The tool uses the real format for the preview and the download.
Characters were changed in transit. A + that went through form encoding often comes back as a space. When a single-line string has spaces and no + at all, the decoder turns the spaces back into +; when both appear, it cannot tell them apart and the image may decode to the wrong bytes. JSON written by some libraries escapes slashes as \/; the decoder removes those escapes and literal \n sequences for you. For anything messier, Repair Base64 lists every fix it makes.
It is encoded twice. If the decoded bytes are themselves Base64 text, a note says so and Decode again unwraps the next layer. Back returns to the previous step. The same works for data URIs inside Base64 and for gzip- or zlib-compressed data.
The browser cannot show the format. HEIC photos from iPhones display only in Safari 17 and later, TIFF only in Safari, and JPEG XL needs Safari 17, Chrome 155 or Firefox 158 or newer. The preview then says the browser cannot display it, but the bytes are intact: Download file saves a working file that a photo app can open.
It is not an image. A Base64 string that starts JVBER is a PDF and UEsDB is a ZIP archive. Use Base64 to File, which previews documents, archives, audio and more.
Saving with the right extension
The Extension and MIME type fields are filled in from the detected format until you edit them, so a PNG is saved as .png even if nothing in the input said “PNG”. Windows and upload forms judge a file by its extension. If you rename a WebP to .jpg, it is still WebP inside, and strict software will reject it.
You can override both fields, for example to save an icon as .cur or to type a MIME type of your own. A changed MIME type also re-renders the preview with that type.
SHA-256 and hex dump
The SHA-256 hash under the preview is calculated over the decoded bytes. Compare it with a hash from the sender, a database record or sha256sum image.png to prove that the picture you saved is the exact file that was encoded, byte for byte. For hashing other data, see the SHA-256 tool.
Show hex dump displays the first 512 bytes. It is the quickest way to inspect a header: the PNG width and height at offset 0x10, the Exif marker in a camera JPEG, or the image directory of an ICO file.
Privacy: images stay on your device
Base64 images are often things you would not upload to a random website: screenshots from a bug report, scans of an ID card or passport, medical images exported from a patient portal, signatures captured on a tablet. This page decodes them entirely in your browser. The page’s Content Security Policy blocks network requests from its scripts, except Cloudflare’s page-view count, and Download file saves from a local blob: URL. Nothing you paste is stored by the site.
Decode a Base64 image in code
In Python, strip the prefix, restore padding and pick the extension from the signature:
import base64, re
def save_image(b64: str, stem: str = "image") -> str:
b64 = re.sub(r"^data:[^,]*;base64,", "", b64.strip(), flags=re.I)
b64 = re.sub(r"\s+", "", b64).replace("-", "+").replace("_", "/")
data = base64.b64decode(b64 + "=" * (-len(b64) % 4))
if data.startswith(b"\x89PNG"):
ext = "png"
elif data.startswith(b"\xff\xd8\xff"):
ext = "jpg"
elif data.startswith(b"GIF8"):
ext = "gif"
elif data[:4] == b"RIFF" and data[8:12] == b"WEBP":
ext = "webp"
else:
ext = "bin"
with open(f"{stem}.{ext}", "wb") as f:
f.write(data)
return f"{stem}.{ext}"
In the browser, turn the string into a Blob and show it through an object URL:
function base64ToBlob(b64, type = "image/png") {
const bin = atob(b64.replace(/^data:[^,]*;base64,/, "").replace(/\s+/g, ""));
const bytes = Uint8Array.from(bin, c => c.charCodeAt(0));
return new Blob([bytes], { type });
}
img.src = URL.createObjectURL(base64ToBlob(str));
More on reading and writing binary data is on Base64 in Python and Base64 in JavaScript. For the opposite direction, Image to Base64 encodes a picture, with resizing and format conversion.
FAQ
Do I need the data:image/png;base64, prefix?
No. Bare Base64 works, and the type is read from the decoded bytes. If you paste a full data URI, the prefix is removed for you and the declared type is checked against the content.
How do I know which image format a Base64 string is?
Look at the first characters: iVBORw0KGgo is PNG, /9j/ is JPEG, R0lGOD is GIF, UklGR is a RIFF file such as WebP. Paste it above and the Detected field names the format for you.
Why does the decoded image look cut off at the bottom?
The Base64 string was truncated when it was copied, logged or stored. Browsers draw what they can of an incomplete PNG or JPEG. Copy the value again from the source; no tool can restore bytes that are not in the string.
Is it safe to decode screenshots or ID photos here?
The decoding happens in this page’s JavaScript, and its Content Security Policy blocks every network request from the page except Cloudflare’s page-view count, so the image is not sent anywhere. You can watch the network panel of your browser’s developer tools while you decode to confirm it.
Can it convert the decoded image to another format?
No, it saves the exact bytes that were encoded. To get a PNG, JPEG or WebP version, download the file and run it through Image to Base64 with Convert to, then decode the result.