Base64 PNG Decoder
Decode Base64 encoded PNG strings to viewable images instantly. Preview, inspect metadata, and download decoded PNG files client-side.
data:image/png;base64, prefix. Whitespace is ignored.
About
A Base64-encoded PNG string inflates the original binary by roughly 33% due to the 6-bit-to-8-bit encoding ratio. Passing a malformed string to a naive decoder produces a silent blank image or a broken src attribute that is impossible to debug without inspecting the raw bytes. This tool validates the input against the PNG magic signature (89 50 4E 47 0D 0A 1A 0A) before rendering, parses the IHDR chunk for width, height, bit depth, and color type, and reports the decoded file size in bytes. It operates entirely in-browser with zero server round-trips.
Limitation: the tool decodes standard Base64 (RFC 4648). Base64url variants using - and _ instead of + and / are auto-converted, but non-PNG payloads (JPEG, GIF, WebP) will be rejected at the signature check. Maximum practical input size depends on browser memory - strings above 50MB may cause tab crashes on mobile devices.
Formulas
The decoded byte size S from a Base64 string of length L with p padding characters is computed as:
Where S = decoded size in bytes, L = length of Base64 string (excluding whitespace and data URI prefix), p = number of trailing = padding characters (0, 1, or 2).
PNG signature validation checks the first 8 decoded bytes against the constant sequence:
Image dimensions are extracted from the IHDR chunk via big-endian 32-bit unsigned integer reads:
Where uint32BE reads four consecutive bytes as a big-endian unsigned 32-bit integer: b0 ร 224 + b1 ร 216 + b2 ร 28 + b3.
Reference Data
| Property | IHDR Offset | Size | Description |
|---|---|---|---|
| Signature | Byte 0 - 7 | 8 bytes | PNG magic number: 89 50 4E 47 0D 0A 1A 0A |
| IHDR Length | Byte 8 - 11 | 4 bytes | Always 13 (0x0000000D) |
| IHDR Type | Byte 12 - 15 | 4 bytes | Chunk type: 49 48 44 52 ("IHDR") |
| Width | Byte 16 - 19 | 4 bytes | Image width in pixels (big-endian uint32) |
| Height | Byte 20 - 23 | 4 bytes | Image height in pixels (big-endian uint32) |
| Bit Depth | Byte 24 | 1 byte | Bits per sample: 1, 2, 4, 8, or 16 |
| Color Type | Byte 25 | 1 byte | 0=Grayscale, 2=RGB, 3=Indexed, 4=Gray+Alpha, 6=RGBA |
| Compression | Byte 26 | 1 byte | Always 0 (deflate/inflate) |
| Filter Method | Byte 27 | 1 byte | Always 0 (adaptive filtering) |
| Interlace | Byte 28 | 1 byte | 0=None, 1=Adam7 |
| Base64 Ratio | - | - | Encoded size รท decoded size ≈ 1.333 |
| Padding | - | - | 0 - 2 = chars appended to make length divisible by 4 |
| Data URI Prefix | - | - | data:image/png;base64, |
| Max Channels (RGBA) | - | - | 4 channels ร bit depth per pixel |
| CRC-32 | Byte 29 - 32 | 4 bytes | Checksum over IHDR type + data |
| Alphabet (Standard) | - | - | A-Z a-z 0-9 + / = (64 symbols + pad) |
| Alphabet (URL-safe) | - | - | A-Z a-z 0-9 - _ (no padding) |