Base64 Image Decoder

Decode Base64 data URIs back to viewable images

Base64 Input

What Is Base64 Image Decoding?

Base64 image decoding is the reverse of Base64 image encoding: it takes a Base64 string or data URI that represents an image and converts it back into viewable binary pixel data. When you receive a string like data:image/png;base64,iVBORw0KGgo..., decoding strips the data URI prefix, reverses the Base64 encoding defined in RFC 4648, and reconstructs the original image bytes. The browser can then render the decoded bytes as a visible image.

Data URIs (RFC 2397) bundle the MIME type and Base64-encoded content into a single string. They appear frequently in API responses, HTML email source code, CSS stylesheets, and database records where images are stored as text rather than binary files. Decoding these strings is necessary to preview the image, verify its content, or save it as a standalone file. Because Base64 uses 4 ASCII characters to represent every 3 bytes of binary data, the encoded string is always approximately 33% larger than the original image.

This tool parses both full data URIs (data:image/png;base64,...) and raw Base64 strings without the data: prefix. For raw strings, the image format is detected automatically by inspecting the first few Base64 characters, which correspond to the file's magic bytes β€” for example, iVBORw0KGgo always indicates a PNG file. The decoded image is rendered directly in the browser and can be downloaded as a file.

A common developer scenario is working with a REST API that returns a profile photo or document thumbnail as a Base64 string inside a JSON field β€” for example, {"avatar": "data:image/png;base64,iVBORw0KGgo..."}. To use the image, you extract the field value, strip the data URI prefix up to and including the comma, then feed the remaining Base64 characters through a decoder such as atob() in JavaScript or base64.b64decode() in Python to recover the raw bytes. Pasting the full value into this tool skips all of those manual steps and renders the image immediately.

Why Use This Base64 Image Decoder?

This tool converts Base64 image data back to a viewable, downloadable image entirely in your browser β€” no upload, no server processing, no account required.

⚑
Instant Preview
Paste a Base64 string or data URI and see the decoded image immediately. No waiting for server-side processing β€” the browser decodes and renders the result locally.
πŸ”’
Privacy-First Processing
Your image data never leaves your device. Decoding runs entirely in the browser using native JavaScript APIs. No Base64 strings are transmitted to any server.
πŸ–ΌοΈ
Automatic Format Detection
Supports PNG, JPEG, SVG, WebP, GIF, BMP, and ICO. The MIME type is extracted from the data URI prefix or detected automatically from the Base64 magic bytes when no prefix is present.
πŸ“‹
Download the Result
Save the decoded image as a file with the correct extension. The download uses the detected format β€” no manual renaming from .txt to .png required.

Base64 Image Decoding Use Cases

Frontend Debugging
Inspect Base64-encoded images embedded in HTML, CSS, or JavaScript source code. Paste the data URI to verify that the correct image is being rendered before deploying.
API Response Inspection
REST and GraphQL APIs often return images as Base64 strings in JSON payloads β€” user avatars, document thumbnails, or QR codes. Decode them to verify the content matches expectations.
Email Template Development
HTML emails frequently embed images as data URIs to bypass external-image blocking. Decode the Base64 to preview what recipients will see without sending a test email.
Database Record Verification
When images are stored as Base64 text in database columns (MongoDB, PostgreSQL text fields), decode sample records to confirm data integrity after migrations or imports.
Security Analysis
Inspect suspicious Base64 image payloads in logs, emails, or web traffic. Decoding reveals the actual image content and format, helping identify tracking pixels or unexpected embedded data.
Learning and Education
Understand how Base64 encoding works by encoding an image, then decoding it back. Compare the original file with the round-tripped result to verify that Base64 is a lossless encoding.

Data URI Structure for Images

A data URI packages the image type and encoded content into a single string. Each component is essential for correct decoding: the scheme (data:) signals that the URL is self-contained rather than a reference to an external resource; the MIME type (e.g., image/png) tells the renderer which format to use when interpreting the raw bytes; the ;base64, marker distinguishes Base64-encoded content from data URIs that use percent-encoding for plain text formats. The Base64 payload itself may end with one or two = padding characters β€” these are required when the input byte count is not a multiple of three, ensuring the encoded length is always a multiple of four. Omitting or truncating any of these components causes decoding to fail or produce a corrupt image.

ComponentDescription
data:URI scheme identifier
image/pngMIME type declaring the image format
;base64,Encoding declaration (always base64 for binary)
iVBORw0KGgo...Base64-encoded pixel data

Detecting Image Format from Base64

When a Base64 string lacks a data: prefix, the image format can be identified by inspecting the first few characters. These characters correspond to the file's magic bytes β€” fixed byte sequences at the start of every image file that identify the format:

FormatBase64 PrefixHex SignatureMIME Type
PNGiVBORw0KGgo89 50 4E 47image/png
JPEG/9j/FF D8 FFimage/jpeg
GIFR0lGOD47 49 46 38image/gif
WebPUklGR52 49 46 46image/webp
SVGPHN2Zy3C 73 76 67 (text)image/svg+xml
BMPQk42 4Dimage/bmp
ICOAAABAA00 00 01 00image/x-icon

Code Examples

How to decode Base64 image strings back to image files in popular languages and environments:

JavaScript (browser)
// Decode a Base64 data URI to a Blob and create a download link
const dataUri = 'data:image/png;base64,iVBORw0KGgo...'

// Method 1: fetch API (simplest)
const res  = await fetch(dataUri)
const blob = await res.blob()
// blob.type β†’ "image/png", blob.size β†’ 2048

// Method 2: manual decode for older environments
const [header, b64] = dataUri.split(',')
const mime    = header.match(/:(.*?);/)[1]   // β†’ "image/png"
const binary  = atob(b64)
const bytes   = Uint8Array.from(binary, c => c.charCodeAt(0))
const blob2   = new Blob([bytes], { type: mime })

// Create a download link
const url = URL.createObjectURL(blob)
const a   = document.createElement('a')
a.href = url
a.download = 'decoded.png'
a.click()
URL.revokeObjectURL(url)
Python
import base64
import re

data_uri = 'data:image/png;base64,iVBORw0KGgo...'

# Parse the data URI
match = re.match(r'data:(image/[\w+.-]+);base64,(.+)', data_uri)
mime_type = match.group(1)    # β†’ "image/png"
b64_data  = match.group(2)

# Decode and write to file
image_bytes = base64.b64decode(b64_data)
ext = mime_type.split('/')[1].replace('jpeg', 'jpg').replace('svg+xml', 'svg')

with open(f'output.{ext}', 'wb') as f:
    f.write(image_bytes)
# β†’ writes output.png (byte-for-byte identical to the original)

# Decode raw Base64 (no data: prefix)
raw_b64 = 'iVBORw0KGgo...'
image_bytes = base64.b64decode(raw_b64)
Node.js
import { writeFileSync } from 'fs'

const dataUri = 'data:image/png;base64,iVBORw0KGgo...'

// Extract MIME type and Base64 payload
const [meta, b64] = dataUri.split(',')
const mime = meta.match(/:(.*?);/)[1]  // β†’ "image/png"

// Decode to Buffer and save
const buffer = Buffer.from(b64, 'base64')
writeFileSync('output.png', buffer)
// β†’ output.png (identical to the original file)

// Validate by checking magic bytes
console.log(buffer.subarray(0, 4))
// PNG β†’ <Buffer 89 50 4e 47>  (\x89PNG)
// JPEG β†’ <Buffer ff d8 ff e0>
CLI (bash)
# Decode a raw Base64 string to an image file (Linux)
echo 'iVBORw0KGgo...' | base64 -d > output.png

# Decode a raw Base64 string to an image file (macOS)
echo 'iVBORw0KGgo...' | base64 -D > output.png

# Extract Base64 from a data URI and decode
echo 'data:image/png;base64,iVBORw0KGgo...' | \
  sed 's/^data:.*base64,//' | base64 -d > output.png

# Identify the image format from the decoded file
file output.png
# β†’ output.png: PNG image data, 64 x 64, 8-bit/color RGBA

Frequently Asked Questions

What is the difference between a data URI and a raw Base64 string?
A data URI includes a prefix that declares the MIME type and encoding: data:image/png;base64,iVBORw0KGgo.... A raw Base64 string contains only the encoded bytes (iVBORw0KGgo...) with no metadata. This tool accepts both formats. When you paste a raw string, it detects the image format automatically from the Base64 magic bytes.
Does decoding Base64 change the image quality?
No. Base64 is a lossless encoding that converts binary data to ASCII text and back without altering a single byte. The decoded image is byte-for-byte identical to the original file. Any quality differences you notice come from the image format itself (e.g., JPEG compression applied before encoding), not from the Base64 decode step.
How can I tell what format a Base64 image is?
If the string starts with data:image/png;base64, the format is declared in the MIME type. For raw Base64 strings, inspect the first few characters: iVBORw0KGgo indicates PNG, /9j/ indicates JPEG, R0lGOD indicates GIF, and UklGR indicates WebP. These prefixes correspond to each format's magic bytes.
Why does my Base64 string fail to decode?
Common causes include truncated data (the string was cut off during copy-paste), incorrect characters (Base64 uses A-Z, a-z, 0-9, +, / and = for padding), embedded whitespace or line breaks, and a missing or malformed data URI prefix. This tool strips whitespace automatically, but truncated or corrupted data cannot be recovered.
Is it safe to decode Base64 images from untrusted sources?
This tool decodes and renders images in the browser sandbox, which isolates them from your system. However, SVG images can contain embedded JavaScript. Modern browsers block script execution in SVG rendered via img tags or data URIs, but exercise caution with SVGs from untrusted sources. The tool does not execute any scripts from decoded images.
Can I decode Base64 images without an internet connection?
Yes, once the page is loaded. All decoding runs locally in your browser using native JavaScript APIs (atob, Uint8Array, Blob). No network requests are made during the decode process. The tool works identically offline.
What is the maximum Base64 string length this tool can handle?
The practical limit depends on your browser's memory. Most modern browsers handle data URIs of several megabytes without issues. For very large images (10 MB+ encoded), you may experience slower rendering. At that size, decoding programmatically with Node.js or Python and writing directly to a file is more efficient than using a browser-based tool.