← Back to Home

How PNG Compression Works

A practical overview of the PNG format and the techniques used to reduce file size.

By the CompressItAll team. Published 2025-10-26. Updated 2026-10-24.

Compress PNG images with our free tool

Quick Summary

  • PNG uses lossless compression (DEFLATE) with optional pre-compression filters.
  • Optimizations focus on reducing entropy via filtering, palette reduction, and metadata removal.
  • Great for graphics, UI, screenshots, logos, and transparency.
PNG lossless compression: original file size compared to compressed output. Placeholder for real measurement.
Placeholder — replace with real measurement from compressitall.com/compress-png/ (lossless mode)

PNG Building Blocks

PNG files are composed of typed chunks such as IHDR (header), PLTE (palette), IDAT (image data), and IEND (end). The image data is compressed using the DEFLATE algorithm (RFC 1951), as specified in the PNG specification (W3C). Before compression, PNG applies per-row filters to transform pixel values into differences that compress better.

Filters

PNG supports five filters: None, Sub, Up, Average, and Paeth. Each filter predicts the next pixel from neighbors and stores only the difference. Encoders choose the best filter per row to maximize compressibility.

Color Types and Palettes

PNG supports truecolor (RGB/RGBA), grayscale, and indexed color via palettes, as defined in the PNG specification (W3C). When possible, converting to an indexed palette can significantly reduce size while remaining lossless. This is especially effective for logos and UI art with a limited color set. Palettes hold up to 256 entries.

Metadata and Ancillary Chunks

Many PNGs contain optional chunks (textual data, time, gamma, ICC) that are not required for display. Removing unnecessary metadata reduces file size without affecting visual output.

Practical Tips

  • Prefer PNG for graphics with flat colors or transparency. Consider JPEG/WebP/AVIF for photos.
  • Use palette reduction where suitable. Keep alpha channel only if you need transparency.
  • Strip non-essential metadata.

The File Signature and Chunk Layout

Every PNG begins with the same eight-byte signature, which lets software recognise the format even if the file extension is wrong. After that the file is a sequence of chunks. Each chunk has a length, a four-letter type, the data, and a CRC checksum for detecting corruption. Chunks whose type starts with a capital letter are critical and must be understood by every decoder, such as IHDR, PLTE, IDAT and IEND. Chunks that start with a lowercase letter are ancillary, which means a decoder can skip them. That distinction is why metadata can be removed safely: the critical chunks alone are enough to display the picture.

From Pixels to Bytes, Step by Step

  1. The encoder lays out the image as rows of pixels in the chosen color type and bit depth.
  2. For every row it picks one of the five filter types and writes a one-byte filter marker before the row.
  3. The filtered rows are joined into one stream and compressed with DEFLATE, which combines LZ77 matching with Huffman coding.
  4. The compressed stream is split into one or more IDAT chunks and wrapped with the header and end chunks.

Decoding runs the same pipeline backwards, which is why the result is bit-for-bit identical to the input. Filtering does not shrink anything on its own. Its job is to turn the data into a shape DEFLATE handles better.

Why Filtering Helps DEFLATE

DEFLATE looks for repeated byte sequences. A smooth gradient has no exact repeats, because every pixel value is slightly different from the last. After the Sub filter, the same gradient becomes a row of nearly identical small differences, and that repeats very well. The Up filter does the same thing against the pixel above, which suits images with vertical structure. Average blends left and above, and Paeth picks whichever of left, above or upper-left is the closest predictor. Flat areas and sharp edges often prefer a different filter, so encoders choose per row. Better PNG optimizers try several strategies for filter choice and keep the one that produces the smallest stream, which costs encoding time but does not change the picture.

What DEFLATE Is Doing Inside

LZ77 replaces a repeated sequence with a short reference to where it appeared earlier, within a sliding window of recent data. Huffman coding then gives common symbols short bit patterns and rare ones long patterns. Compression levels in PNG tools mostly control how hard the encoder searches for good matches. A higher effort setting can find a smaller result, but the output is always valid DEFLATE that any PNG decoder can read.

Color Types and Bit Depth in Practice

  • Grayscale: one channel per pixel. Use it for genuinely monochrome images.
  • Indexed color: pixels are positions in a palette, and the palette is stored in the PLTE chunk. A palette can hold at most 256 entries.
  • Truecolor: red, green and blue channels, with an optional alpha channel for RGBA.
  • Bit depth: 8 bits per channel is the usual web choice. 16 bits per channel doubles the raw data and rarely helps on screen.

Moving a full-color image to a palette is no longer lossless unless it already had 256 or fewer colors, because colors must be merged. This is the one place where PNG optimization can be lossy, and it is why palette tools show a preview before you commit.

Transparency: Alpha Versus Palette Transparency

RGBA PNGs store a full alpha value for every pixel, which allows smooth shadows and soft edges. Indexed PNGs can also carry transparency through a tRNS chunk that assigns alpha to palette entries. That is cheaper than a full alpha channel but only allows as many transparency levels as there are palette entries. Interlacing (Adam7) is a separate option that shows a rough preview while the image loads, and it normally makes files larger, so leave it off unless progressive display really matters.

Common Misunderstandings

  • "Compressing a PNG again lowers quality." It does not, as long as the pixels stay the same. Only palette reduction or resizing change the image.
  • "A smaller PNG must be lower quality." Often the smaller file just has less metadata or a better filter and DEFLATE choice.
  • "PNG can be made as small as JPEG." For photographs it cannot, because lossless coding of noisy data has a hard floor. See Lossy vs Lossless Compression for when to switch formats.

Browser support: universal (caniuse).

Where to Go From Here

Once the structure makes sense, the practical side is the next step. PNG Optimization Best Practicesturns these ideas into a workflow. To compress a PNG file now, use the is png lossless tool for lossless mode or how does png compression work for the full process. For the sibling formats, How JPEG Compression Works covers the lossy side.

Next Steps

Learn about trade-offs in Lossy vs Lossless Compression, or dive into PNG Optimization Best Practices. When ready, try batch workflows with our Batch Compression Guide.