What is PNG?

Portable Network Graphics (PNG) is a raster image format with lossless compression. It stores indexed-color (palette), grayscale, or RGB images at 1 to 16 bits per sample, each optionally with alpha transparency, and has no CMYK color type.

How PNG works

A PNG datastream is an eight-byte signature followed by chunks, each made of a length, a four-letter type, data, and a CRC. Four chunk types are critical: IHDR (dimensions, bit depth, and color type), PLTE (the palette of an indexed-color image), IDAT (the compressed pixels), and IEND. Before compression, the encoder prefixes each scanline with a filter-type byte that selects either no filtering or one of four filters that store each byte as its difference from a prediction based on neighboring bytes; the filtered stream is then compressed with DEFLATE, the only compression method the specification defines. Both steps are reversible, so decoding returns exactly the samples that were encoded. Ancillary chunks carry optional information such as color space (sRGB, iCCP, cICP), pixel density (pHYs), text, and Exif metadata (eXIf). A decoder may ignore an ancillary chunk it does not recognize, but it must report an unknown critical chunk instead of silently skipping it.

Key facts

  1. PNG compression is lossless, so filter-selection and DEFLATE settings trade encoding time for file size and never change decoded pixels. A lossless optimizer can also shrink a file by removing metadata chunks or by switching to a more compact representation of the same pixels, such as dropping an alpha channel that is fully opaque, so a smaller file alone does not show that pixels changed. Palette quantizers such as pngquant, or encoder options such as sharp’s palette, output a valid indexed-color PNG of at most 256 colors whose pixels may differ from the source.
  2. For color images with 256 or fewer colors, the PNG specification says indexed-color should almost always be used, because truecolor is likely to be much larger. The conversion is exact when the image has at most 256 distinct pixel values, counting alpha, at 8 bits per sample or less. For photographs the format has no lossy mode to fall back on: MDN’s format guide recommends PNG for screenshots, diagrams, and line art and a lossy format for photographs, and a public sharp issue reports a PNG that came out larger than its JPEG source after downscaling.
  3. Transparency comes in three forms. Color types 4 and 6 carry a full alpha channel at 8 or 16 bits per sample. An indexed-color image can list one alpha value per palette entry in a tRNS chunk, so a palette PNG can have partial transparency. For grayscale and truecolor images without an alpha channel, tRNS can only mark a single color value as fully transparent. Stored alpha is not premultiplied into the color samples.
  4. PNG cannot hold CMYK data. Color images are RGB or palette-based, an embedded ICC profile must be an RGB profile (or a grayscale profile for grayscale images), and the specification tells extension authors not to add chunks that reinterpret RGB as CMYK. The color-space chunks (sRGB, iCCP, cICP, or gAMA with cHRM) are optional; without them the specification treats the samples as uncalibrated, device-dependent color, so check that a tool which strips ancillary chunks keeps the ones your colors depend on.

When PNG matters

Choose PNG for screenshots, diagrams, line art, and other sharp-edged graphics, or for assets whose transparency and exact pixels must survive encoding. Photographs and other continuous-tone images usually tolerate lossy compression, so a lossy format is the usual choice there; PNG keeps every sample, which often costs file size on such images.

How Transloadit helps with PNG

Transloadit’s image formats table lists PNG as a format its ImageMagick-based Robots can read and write, and /image/resize names png among its output formats. /image/optimize shrinks PNG files with lossless compressors by default; setting lossy: true also lets pngquant compete, which reduces the image to a 256-color palette.

With lossy: true the smallest of the lossless and lossy results wins, so the output is still a PNG file but is no longer guaranteed to be pixel-identical to the input; the Robot’s documentation warns that color shifts are possible.

Explore Transloadit’s file formats & compression capabilities

Sources

Turn media knowledge into a working pipeline

Connect uploads, processing, AI, storage, and delivery through one declarative API — with the encoding stack, scaling, and format churn handled for you.

Try Transloadit for free