Base64 Image Decoder

Dekode data URI Base64 kembali menjadi gambar yang terlihat

Masukan Base64

Apa Itu Dekode Gambar Base64?

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.

Skenario umum bagi pengembang adalah bekerja dengan REST API yang mengembalikan foto profil atau thumbnail dokumen sebagai string Base64 di dalam bidang JSON, misalnya {"avatar": "data:image/png;base64,iVBORw0KGgo..."}. Untuk menggunakan gambar, Anda mengekstrak nilai bidang, menghapus awalan skema data URI hingga dan termasuk koma, kemudian meneruskan karakter Base64 yang tersisa melalui decoder seperti atob() di JavaScript atau base64.b64decode() di Python untuk memulihkan byte mentah. Menempel nilai lengkap ke alat ini melewati semua langkah manual ini dan merender gambar secara instan.

Mengapa Menggunakan Base64 Image Decoder Ini?

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

โšก
Pratinjau Instan
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.
๐Ÿ”’
Pemrosesan Mengutamakan Privasi
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.
๐Ÿ–ผ๏ธ
Deteksi Format Otomatis
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.
๐Ÿ“‹
Unduh Hasilnya
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.

Kasus Penggunaan Dekode Gambar Base64

Debugging Frontend
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.
Inspeksi Respons API
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.
Pengembangan Template Email
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.
Verifikasi Rekaman Database
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.
Analisis Keamanan
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.
Pembelajaran dan Pendidikan
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.

Struktur Data URI untuk Gambar

A data URI packages the image type and encoded content into a single string. When decoding, each component tells the decoder how to reconstruct the original 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

Mendeteksi Format Gambar dari 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

Contoh Kode

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

Pertanyaan yang Sering Diajukan

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.