To understand how a PNG file is built, start with chunks. A PNG is a sequence of chunks, each carrying a type label, a length, data, and a checksum. Some chunks are required for the image to display. Others are optional and can be lost without damaging the pixels. Learn which chunks matter and which can be dropped, because that is what a repair tool keeps and discards.

The Four Critical Chunks

Required chunks are identified by an uppercase first letter in their four character name. There are exactly four: IHDR, PLTE, IDAT, and IEND. If any of these are missing or damaged beyond repair, the PNG file cannot be decoded. A repair tool must validate and, if possible, reconstruct these chunks from the remaining data.

IHDR the Image Header

The IHDR chunk must come first in the file. It contains 13 bytes of data that describe the fundamental properties of the image:

  • Width (4 bytes)
  • Height (4 bytes)
  • Bit depth (1 byte)
  • Colour type (1 byte)
  • Compression method (1 byte)
  • Filter method (1 byte)
  • Interlace method (1 byte)

The colour type determines how pixel data is stored. PNG supports five colour types: 0 (greyscale), 2 (truecolour RGB), 3 (indexed palette), 4 (greyscale with alpha), and 6 (truecolour with alpha). The bit depth and colour type together define the number of bits per pixel. If IHDR is corrupted, a repair tool must guess or recover these values from the rest of the file, or the image is lost.

PLTE the Palette

The PLTE chunk is required only for colour type 3 (indexed palette). It holds up to 256 palette entries, each entry being three bytes for red, green, and blue. For other colour types, PLTE is optional and can suggest a default palette for display on limited hardware. If PLTE is missing for an indexed colour image, the image cannot be displayed correctly. A repair tool may attempt to reconstruct a default palette or discard the file as unrecoverable.

IDAT the Image Data

The IDAT chunk contains the compressed image data. There can be many consecutive IDAT chunks in a PNG file. They are joined together and decompressed as a single zlib stream. Splitting the data across multiple IDAT chunks does not affect the image; it simply streams or segments the file. If any IDAT chunk is lost or corrupted, the decompressed data will be incomplete or garbled, and the image will be damaged. A repair tool can sometimes salvage parts of the image by reading the uncompressed data that remains intact, but full recovery requires the entire IDAT stream.

IEND the End Marker

The IEND chunk marks the end of the PNG file. It has zero data bytes, so its length field is 0. Without IEND, a decoder does not know where the file ends. If IEND is missing, some decoders may still display the image if they can detect the end of the last IDAT chunk by other means, but the file is technically incomplete. A repair tool can add a valid IEND chunk to fix this.

Ancillary Chunks Metadata and Profiles

What Optional Chunks Carry

Optional chunks have a lowercase first letter in their name. A decoder can ignore them without losing the image pixels. Common optional chunks include tEXt (text metadata), gAMA (gamma correction), pHYs (physical pixel dimensions), iCCP (embedded colour profile), and tIME (last modification time). Losing one of these may change metadata or colour profile but not the pixels. When repairing a corrupted PNG, drop these chunks if they are damaged beyond recovery, as long as the required chunks remain intact.

Which Optional Chunks to Keep

Keep readable optional chunk data for metadata accuracy. Discard corrupted optional chunks without affecting the image. The decision depends on whether the chunk is intact. For example, a broken iCCP chunk might cause colour shifts on some viewers, but the image will still display.

How Optional Chunks Affect Repair

When you repair a PNG file online, the tool must distinguish between required and optional chunks. Required chunks are repaired or reconstructed if possible. Optional chunks are preserved if valid or removed if damaged. This approach maximizes the chance of recovering a viewable image while discarding non essential data.

What a Repair Tool Does with Chunks

The Repair Sequence

  1. Scan the file for chunk boundaries using the length fields and checksums.
  2. Identify each chunk by its four character type name.
  3. Check the checksum for each chunk. If the checksum is valid, the chunk data is considered intact.
  4. For required chunks (IHDR, PLTE, IDAT, IEND), attempt to repair or reconstruct if the chunk is missing or corrupted. For example, if IDAT chunks are fragmented, the tool concatenates them. If IEND is missing, append a new one.
  5. For optional chunks, discard any that are corrupted. Keep intact optional chunks to preserve metadata.
  6. Rebuild the file with the repaired required chunks and any intact optional chunks.

This process ensures the output is a valid PNG file that displays the image. Sites like png.repair offer free online recovery using these principles, without adding watermarks.