.PNG Portable Network Graphics
.png

Portable Network Graphics

PNG was born from a patent protest — created in 1995 after Unisys enforced LZW royalties on GIF. Its 8-byte signature detects transmission corruption, and every chunk carries a CRC-32 checksum. Convert PNG to JPG, WebP, or BMP in your browser with FileDex — no upload, transparency preserved.

Learn more ↓
Image structure
Sig 89 50 4E 47
IHDR width × height
IDAT filtered pixels
LosslessTransparencyW3C1996
By FileDex

Your files never leave your device

Common questions

Why are my PNG files so much larger than JPEGs of the same image?

PNG uses lossless DEFLATE compression, which preserves every pixel exactly. For photographic content, this produces files 5-20x larger than JPEG because JPEG DCT compression discards perceptual redundancy that DEFLATE cannot. PNG is designed for graphics, screenshots, and images with text — not photographs.

Does converting PNG to JPG lose quality?

Yes. JPEG is a lossy format, so conversion discards some image data during DCT quantization. Transparent areas are flattened to a solid background color (typically white). For photographs, the quality difference at JPEG quality 85+ is minimal. For graphics with sharp edges or text, JPEG artifacts are more visible.

Can I make a PNG file smaller without losing quality?

Use a lossless PNG optimizer that tests different compression parameters without altering any pixels, typically saving 5-15%. For larger reductions, tools that reduce to 8-bit indexed color with dithering can cut file size by 60-80% — technically lossy but visually imperceptible for most web graphics. See the CLI tab in Technical Reference below for the exact commands.

Why does my PNG have a black background when I convert it to JPG?

PNG alpha transparency has no equivalent in JPEG. When converting without specifying a background, decoders map transparent pixels to black (RGBA 0,0,0,0 becomes RGB 0,0,0). Use ImageMagick with -background white -flatten to composite onto a white background before encoding to JPEG.

Why are my screenshots so large as PNG files?

A 1920x1080 screenshot at 32 bits/pixel (RGBA) is 8.3 MB of raw pixel data before compression. DEFLATE reduces this to 500 KB-3 MB depending on content. Screenshots of text and flat UI elements compress well because adjacent pixels are identical. Screenshots of photos or gradients compress poorly due to high pixel entropy.

What is the difference between PNG-8 and PNG-24?

PNG-8 uses indexed color with a palette of up to 256 colors (8 bits per pixel). PNG-24 uses truecolor with 16.7 million colors (24 bits per pixel). PNG-8 files are 3-5x smaller but lose detail in photographs. Use PNG-8 for icons and simple graphics, PNG-24 for screenshots and images needing color accuracy.

Should I use PNG or WebP for web images?

WebP lossless produces files approximately 26% smaller than PNG at identical quality. WebP also supports lossy compression and animation. All major browsers support WebP since 2020. Use PNG when you need maximum compatibility with legacy tools or email clients that reject WebP. For web delivery, WebP is the better choice.

Does PNG support animation?

APNG (Animated PNG) was officially incorporated into the PNG 3.0 specification in June 2025. All major browsers — Chrome, Firefox, Safari, Edge — support APNG. Unlike GIF, APNG supports 24-bit color with full alpha transparency. Non-APNG decoders display the first frame as a static image, maintaining backward compatibility.

What makes .PNG special

Patent protest
Created to replace patent-locked GIF
Unisys enforced LZW patent fees on GIF in 1994. The web community built PNG as a free alternative with better color and transparency.
CRC on every chunk
Built-in corruption detection
Every PNG chunk carries a CRC-32 checksum. If a single bit flips during transfer, the decoder knows exactly which chunk is damaged.
Alpha channel
256 levels of transparency per pixel
PNG supports full 8-bit alpha — smooth drop shadows, glass effects, anti-aliased edges. GIF only has binary on/off transparency.
Filter rows
5 prediction filters per scanline
Before compression, PNG transforms each row using Sub, Up, Average, or Paeth prediction. Optimal filter selection can shrink files by 5-15%.

PNG compresses raster images losslessly using DEFLATE, the same algorithm inside ZIP and gzip. Every pixel survives encoding and decoding intact — no generation loss, no quality settings, no artifacts. This makes PNG the default format for screenshots, UI assets, diagrams, and any image where pixel-perfect reproduction matters.

Continue reading — full technical deep dive

DEFLATE compression pipeline

PNG's compression works in two stages. First, LZ77 finds repeated byte sequences within a sliding window (32 KB by default) and replaces duplicates with back-references (distance, length pairs). Then Huffman coding assigns shorter bit patterns to frequently occurring symbols. The combination is lossless and deterministic — the same input always produces the same output given identical encoder settings.

Before DEFLATE runs, PNG applies a per-row filter that transforms raw pixel values into differences more amenable to compression. This preprocessing step is critical to PNG's effectiveness.

Filter rows

Each scanline begins with a filter-type byte (0–4) declaring which transform was applied:

Filter Operation Best for
None (0) Raw pixel values, no transform Random noise, dithered images
Sub (1) Difference from pixel to the left Horizontal gradients
Up (2) Difference from pixel above Vertical gradients
Average (3) Difference from mean of left + above Smooth areas with diagonal gradients
Paeth (4) Difference from Paeth predictor (left, above, or upper-left, whichever is closest) Photographic content, mixed patterns

Encoders choose a filter per row independently. Optimal selection runs all five filters on each row and picks the one that minimizes entropy. This brute-force approach (used by optipng level 5 and above) can shrink files 5–15% compared to a fixed filter strategy, at the cost of slower encoding.

Chunk-based file structure

PNG files are built from typed chunks, each with a 4-byte name, length, data, and CRC32 checksum. Critical chunks that every decoder must understand:

  • IHDR — image header (first chunk): width, height, bit depth, color type, compression method, interlace flag
  • IDAT — one or more chunks containing the compressed pixel data
  • IEND — empty terminator marking end of file

Ancillary chunks carry optional data:

  • tEXt / iTXt — key-value text metadata (title, author, description, copyright)
  • gAMA — gamma value for cross-platform color consistency
  • tRNS — simple transparency for indexed and grayscale images without a full alpha channel
  • pHYs — physical pixel dimensions (DPI)
  • iCCP — embedded ICC color profile
  • acTL / fcTL / fdAT — APNG animation control and frame data

The chunk system is extensible by design. Unknown ancillary chunks are silently ignored by decoders, so custom metadata can be embedded without breaking compatibility.

Color types and bit depths

PNG supports five color types, each with specific bit depth options:

Color type Channels Bit depths Typical use
Grayscale (0) 1 1, 2, 4, 8, 16 Masks, line art
Truecolor (2) 3 (RGB) 8, 16 Photos, renders
Indexed (3) 1 (palette index) 1, 2, 4, 8 Icons, pixel art, simple graphics
Grayscale + alpha (4) 2 8, 16 Transparency masks
Truecolor + alpha (6) 4 (RGBA) 8, 16 UI elements, compositing layers

Indexed-color PNG stores a palette of up to 256 colors in a PLTE chunk. For images with few unique colors, this slashes file size dramatically — a 256-color icon at 64x64 might weigh 2 KB as indexed PNG versus 12 KB as truecolor.

Alpha channel transparency

PNG's alpha channel stores per-pixel opacity at 8-bit (256 levels) or 16-bit (65,536 levels) precision. This is fundamentally different from GIF's binary transparency, where each pixel is either fully opaque or fully transparent. Semi-transparent drop shadows, glass effects, anti-aliased edges against arbitrary backgrounds — these require the smooth gradation only a full alpha channel provides.

For truecolor PNG, alpha adds one byte per pixel at 8-bit depth. A 1920x1080 RGBA image contains 8.3 million bytes of raw pixel data before compression, versus 6.2 million for RGB. The overhead is roughly 33% in raw terms, though DEFLATE compresses the alpha channel efficiently when it contains large uniform regions.

File size characteristics

A 1920x1080 PNG screenshot averages 1.2–2.8 MB; the same image saved as JPEG at quality 85 drops to 180–400 KB. The gap grows with photographic complexity. Screenshots of text and UI elements compress well in PNG because of large uniform color regions. Photographs compress poorly because every pixel differs from its neighbors, defeating both the row filters and LZ77's duplicate-finding.

This size difference is PNG's primary practical limitation. For photographic web content, JPEG or WebP lossy at quality 80–85 produces visually identical results at 5–15x smaller file sizes.

Adam7 interlacing

PNG optionally supports Adam7 interlacing, which rearranges pixels into seven sub-images of increasing resolution. The browser can render a blurry preview after receiving roughly 1/64th of the pixel data, progressively sharpening as more data arrives.

The tradeoff is significant. Interlaced PNGs are typically 10–15% larger than non-interlaced equivalents because each sub-image compresses independently with less context for DEFLATE to exploit. On modern connections where full images load in milliseconds, the progressive rendering benefit rarely justifies the size penalty. Non-interlaced is the default for good reason.

Gamma correction pitfalls

The gAMA chunk declares the gamma value used when the image was created. Decoders are supposed to apply gamma correction to ensure consistent appearance across displays. In practice, this causes more problems than it solves.

macOS historically used gamma 1.8; Windows used 2.2. A PNG created on macOS with an embedded gAMA of 1.8 appears washed-out on Windows if the decoder honors the chunk, and correct if it ignores it. Firefox, Chrome, and Safari all handle gAMA differently depending on whether an ICC profile is also present. Many web developers strip gAMA and sRGB chunks entirely (using pngcrush -rem gAMA -rem sRGB) to avoid cross-platform color shifts.

Optimization tools

PNG encoders vary wildly in output size. The chain for maximum compression:

  1. pngquant — lossy step: reduces truecolor to indexed 256-color using median-cut quantization with Floyd-Steinberg dithering. Produces 60–80% smaller files. Visually indistinguishable for UI screenshots and most web graphics.
  2. optipng — lossless: tries multiple DEFLATE strategies and filter combinations, picks the smallest result.
  3. zopfli — lossless: Google's DEFLATE implementation that spends 80–100x more CPU time finding optimal matches. Produces files 3–8% smaller than standard DEFLATE. Decode speed is identical since the format is unchanged.

For automated pipelines, pngquant alone handles 90% of the optimization opportunity. Adding optipng or zopfli yields diminishing returns.

APNG animation

APNG extends PNG with animation capabilities through three additional chunk types: acTL (animation control), fcTL (frame control), and fdAT (frame data). Each frame is a full PNG image compressed independently, with optional dispose and blend operations for inter-frame efficiency.

APNG is supported in all modern browsers since Firefox 3 (2008) and Chrome 59 (2017). It supports full alpha transparency per frame — something GIF cannot do. File sizes run larger than equivalent WebP animations but smaller than frame-extracted GIF sequences at comparable quality.

When to use PNG

Use PNG for screenshots, line art, text renders, UI sprites, icons, diagrams, anything requiring transparency, and any image where lossy artifacts are unacceptable.

Use JPEG instead for photographs and complex textures where lossy compression is acceptable. JPEG at quality 85 produces files 5–15x smaller with imperceptible quality loss on photographic content.

Use WebP instead when browser support permits (95%+ global coverage as of 2025). WebP lossy beats JPEG by ~25% at equivalent quality; WebP lossless beats PNG by 20–30% on typical web graphics.

Use SVG instead for geometric illustrations, logos, and icons that must scale to arbitrary resolution. SVG files are resolution-independent and typically smaller than equivalent PNG renders at high DPI.

.PNG compared to alternatives

.PNG compared to alternative formats
Formats Criteria Winner
.PNG vs .JPG
Quality preservation for screenshots and graphics
PNG DEFLATE lossless compression preserves every pixel exactly. JPEG DCT introduces visible blocking artifacts on hard edges, text, and solid color boundaries.
PNG wins
.PNG vs .WEBP
Lossless compression efficiency
WebP VP8L lossless produces files approximately 26% smaller than PNG for equivalent content, using more advanced prediction and entropy coding.
WEBP wins
.PNG vs .GIF
Color depth and transparency
PNG supports up to 48-bit RGB with full 8/16-bit alpha channel. GIF is limited to 256 indexed colors with binary (1-bit) transparency.
PNG wins
.PNG vs .TIFF
Web delivery suitability
PNG is universally supported in browsers with efficient DEFLATE compression. TIFF has no native browser support and produces much larger files for equivalent lossless content.
PNG wins

Technical reference

MIME Type
image/png
Magic Bytes
89 50 4E 47 0D 0A 1A 0A 8-byte PNG signature with DOS/Unix line ending detection bytes.
Developer
PNG Development Group (W3C)
Year Introduced
1996
Open Standard
Yes — View specification
0000000089504E470D0A1A0A .PNG....

8-byte PNG signature with DOS/Unix line ending detection bytes.

Binary Structure

PNG uses a chunk-based structure. The file begins with an 8-byte signature (89 50 4E 47 0D 0A 1A 0A) designed to detect transmission errors and file type misidentification. All data after the signature is organized into chunks, each with a 4-byte length, 4-byte type code, variable data, and 4-byte CRC32 checksum. Critical chunks (IHDR, IDAT, IEND) must be present. IHDR is always first, IEND always last. IDAT chunks contain DEFLATE-compressed filtered scanline data. Ancillary chunks (tEXt, gAMA, sRGB, iCCP, tRNS) are optional.

OffsetLengthFieldExampleDescription
0x00 8 bytes PNG Signature 89 50 4E 47 0D 0A 1A 0A Fixed signature. Byte 0x89 detects 8-bit transmission. Bytes 0D 0A detect CR-LF conversion. Byte 1A stops display under DOS.
0x08 4 bytes IHDR length 00 00 00 0D IHDR data is always 13 bytes.
0x0C 4 bytes IHDR type 49 48 44 52 ASCII 'IHDR' — image header chunk type code.
0x10 4 bytes Width 00 00 04 00 Image width in pixels (big-endian uint32). Example: 1024.
0x14 4 bytes Height 00 00 03 00 Image height in pixels (big-endian uint32). Example: 768.
0x18 1 byte Bit depth 08 Bits per sample: 1, 2, 4, 8, or 16.
0x19 1 byte Color type 06 0=grayscale, 2=RGB, 3=indexed, 4=grayscale+alpha, 6=RGBA.
variable variable IDAT chunk(s) 49 44 41 54 Contains DEFLATE-compressed filtered scanline data. May span multiple chunks.
EOF-12 12 bytes IEND chunk 00 00 00 00 49 45 4E 44 AE 42 60 82 Empty chunk (0-byte data). Marks end of PNG data stream. CRC is always AE 42 60 82.
1995PNG format conceived as patent-free GIF replacement after Unisys began enforcing LZW patents1996PNG 1.0 published as W3C Recommendation (RFC 2083)1998PNG receives ISO/IEC 15948 standardization2003PNG 1.2 specification released with revised recommendations2004APNG (Animated PNG) proposed by Mozilla as animated PNG extension2017All major browsers achieve full PNG support including APNG animation
Convert PNG to JPG with white background imagemagick
magick input.png -background white -flatten -quality 85 output.jpg

Flattens the alpha channel onto a white background and encodes to JPEG at quality 85. Without -flatten, transparent areas render as black in JPEG output.

Convert PNG to lossless WebP other
cwebp -lossless input.png -o output.webp

Encodes PNG to WebP lossless mode (VP8L). Produces approximately 26% smaller files than PNG while preserving alpha transparency and all pixel data exactly.

Optimize PNG file size with maximum compression imagemagick
magick input.png -strip -define png:compression-level=9 -define png:compression-strategy=1 output.png

Strips metadata and applies maximum DEFLATE compression level. Strategy 1 (filtered) works best for photographic content. Lossless — no pixel data changes.

Extract PNG dimensions and color info ffprobe
ffprobe -v error -show_entries stream=width,height,pix_fmt,bits_per_raw_sample -of json input.png

Reports image dimensions, pixel format (rgb24, rgba, gray, etc.), and bit depth without decoding the full image data.

PNG JPG transcode lossy JPEG DCT compression produces 5-20x smaller files for photographic content where lossless fidelity is unnecessary. Alpha channel is flattened to a white or specified background color during conversion.
PNG WEBP transcode variable WebP lossless mode (VP8L) produces 26% smaller files than PNG on average per Google's study, while preserving alpha transparency. WebP lossy mode offers even greater reduction for photographs originally stored as PNG.
PNG BMP transcode lossless BMP stores raw uncompressed pixel data compatible with legacy Windows applications and embedded hardware that lacks PNG decompression capability.
LOW

Attack Vectors

  • Decompression bomb — crafted PNG with small file size that expands to gigabytes of pixel data during decoding (e.g., 64KB PNG expanding to 4GB RGBA buffer)
  • CRC bypass — corrupted chunks with valid CRC that exploit parser assumptions about data integrity
  • Integer overflow in IHDR dimensions — extremely large width/height values can cause memory allocation overflow in naive decoders

Mitigation: FileDex decodes PNG entirely in the browser sandbox via Canvas API. Maximum decoded dimensions are constrained by browser canvas limits (typically 16384x16384 or 268 megapixels). No server upload occurs.

libpng library
Official PNG reference library used by most PNG implementations
pngquant tool
Lossy PNG compressor that reduces 24/32-bit PNG to 8-bit indexed palette
OptiPNG tool
Lossless PNG optimizer that finds optimal DEFLATE parameters
ImageMagick tool
CLI image processor with full PNG read/write including all chunk types
sharp library
High-performance Node.js image processing built on libvips with PNG support