What Is a PNG File? Structure, Uses and Limits
Understand what PNG stores, how to identify it and when it is the right format.
What a PNG File Actually Stores
A Portable Network Graphics file is a structured container that holds pixel data plus optional metadata in strictly ordered, self-contained chunks. The format is defined by the W3C in the PNG specification (ISO/IEC 15948, mirrored at https://www.w3.org/TR/png-3/). Four mandatory categories of information exist in every valid PNG:
- Pixel array — Colour values for each pixel, encoded in one of five colour types: greyscale (1, 2, 4, 8, or 16 bits per sample), greyscale with alpha, truecolour (RGB, 8 or 16 bits per sample), truecolour with alpha, or indexed-colour (palette-based, up to 8 bits per pixel). The specification mandates Deflate compression (RFC 1951) for all pixel data. Interlaced images use the Adam7 interlacing pattern, which stores the image as seven progressively refined sub-images.
- Colour space metadata — The
gAMAchunk stores gamma correction;cHRMstores chromaticity coordinates;sRGBindicates an sRGB rendering intent;iCCPembeds an ICC colour profile. When none of these chunks are present, a decoder must assume sRGB or fall back to an unspecified display calibration. - Transparency data — For indexed images, the
tRNSchunk maps individual palette entries to alpha values. For greyscale and truecolour images without a full alpha channel, it defines a single transparent colour. For images with a full alpha channel (colour types 4 and 6), transparency is encoded per pixel in the pixel array itself. - Ancillary metadata — Textual metadata (
tEXt,zTXt,iTXt), physical pixel dimensions (pHYs), suggested background colour (bKGD), image histogram (hIST), and a limited set of other optional chunks. The specification explicitly forbids thumbnail images stored as separate chunks; any preview must be the full image rendered at reduced size or stored in a companion file.
A critical structural rule governs every PNG: the first eight bytes are a fixed signature (89 50 4E 47 0D 0A 1A 0A). Any file that does not begin with this exact byte sequence is not a PNG, regardless of its file extension. After the signature, the file must contain exactly one IHDR (image header) chunk, followed by one or more IDAT (image data) chunks, and end with a single IEND (image end) chunk. Critical chunks (IHDR, PLTE when required by colour type 3, IDAT, IEND) must appear exactly once and in that relative order.
How to Validate a PNG File
A .png file extension is not proof of validity. To confirm that a file is a genuine, well-formed PNG, check these four properties:
- Byte signature — The first eight bytes must match the PNG magic number. Use a hex editor or the
filecommand on Unix/macOS (file --mime-type image.png). Any mismatch means the file is either corrupted or mislabeled. - Chunk structure — A valid PNG must contain at least one
IDATchunk. Tools such aspngcheck(part of libpng) oridentify -verbose(ImageMagick) report missing critical chunks and invalid CRC-32 checksums on a per-chunk basis. A CRC mismatch on any critical chunk renders the file unreadable. - Pixel data integrity — Even with correct chunk structure, the compressed pixel data may be corrupted. The Deflate stream inside
IDATchunks is self-checking; a decompression error is unrecoverable. The PNG specification provides no forward error correction. If any bit in the compressed stream is wrong, the entire image is lost. - Colour type and bit depth constraints — The
IHDRchunk encodes colour type (0, 2, 3, 4, or 6) and bit depth (1, 2, 4, 8, or 16). Not every combination is valid. Colour type 3 (indexed-colour) cannot use bit depth 16. Colour type 2 (truecolour) cannot use bit depths 1, 2, or 4. A file that violates these constraints is malformed and must be rejected by a conforming decoder.
Hard Structural Limits
The PNG specification imposes absolute limits that cannot be worked around:
- Maximum pixel dimensions — The width and height fields in
IHDRare 32-bit unsigned integers, giving a theoretical maximum of 4,294,967,295 pixels per side. In practice, software and memory limits are reached far sooner. libpng defaults to a maximum of 1,000,000 pixels per side unless explicitly overridden. - Maximum chunk size — Individual
IDATchunks are limited to 2³¹−1 bytes (approximately 2 GiB). A PNG with multipleIDATchunks can exceed this total, but many decoders abort on any single chunk larger than 2 GiB. - Colour depth — PNG supports only 8 or 16 bits per sample per channel. It does not support 10-bit or 12-bit colour natively. For high-dynamic-range imaging, formats such as OpenEXR or TIFF with 32-bit floating-point samples are required.
- Metadata capacity — Text chunks have no size limit in the specification, but some decoders silently truncate metadata longer than 65,535 bytes. The
iCCPprofile chunk is similarly unbounded, yet many applications reject profiles larger than 1 MiB. - Animation — PNG itself supports only one static raster frame per file. Animated PNG (APNG) and MNG are separate formats with their own specifications and decoder requirements.
When to Use PNG
PNG is optimal when every pixel must be preserved exactly. Lossless compression means that re-saving a PNG does not degrade quality, unlike JPEG, which loses data on every encode-decode cycle. This makes PNG the correct choice for images containing sharp edges, text, line art, or solid areas of uniform colour, and for any image that will undergo multiple rounds of editing and re-saving.
For images with fewer than 256 distinct colours, PNG’s indexed-colour mode (colour type 3) produces files that are often smaller than GIF equivalents while supporting full 8-bit alpha transparency per palette entry. For greyscale images such as medical scans or document archives, PNG’s 16-bit greyscale support preserves tonal precision that JPEG’s 8-bit luminance encoding discards.
When PNG Is the Wrong Choice
PNG is a poor choice for photographic images destined for the web where file size is the primary constraint. A typical 24-bit photograph compressed with PNG is often 2–5 times larger than a JPEG at equivalent visual quality, and larger than lossy WebP at comparable file size. PNG does not support multi-page documents, embedded audio, or any form of animation within the core specification.
The PNG specification itself states that the format was designed “for transfer and display of images on the World Wide Web” and is “not intended as a general-purpose graphics interchange format.” That limitation remains accurate.
Decision Boundaries Against Alternative Formats
Choose PNG over JPEG when accuracy is paramount: medical imaging, archival scans, diagrams, screenshots, and any image that will be edited and re-saved. Choose PNG over GIF for indexed-colour images; PNG supports 8-bit indexed colour with full alpha, while GIF supports only 1-bit binary transparency. Choose PNG over TIFF when universal browser support is required—all modern browsers render PNG natively, while TIFF often requires a plugin or separate download.
Choose JPEG, WebP, or AVIF over PNG when file size is the primary constraint and minor loss of quality is acceptable. Choose TIFF over PNG for multi-page documents or when 32-bit floating-point colour depth is needed. Choose SVG over PNG when the image must scale to arbitrary sizes without pixelation.