PNG file format
Portable Network Graphics, a lossless raster image format.
- MIME type
- image/png
- Extensions
- .png
- Category
- Images
Magic-number signature
| 0x00000000 | 89504E470D0A1A0A | ·PNG···· | PNG magic + CRLF guard |
About the PNG format
PNG stores images without any quality loss and supports full alpha transparency, which makes it the default choice for screenshots, logos, icons and any graphic with sharp edges. Every PNG opens with an eight-byte signature that includes a newline pair so the file is corrupted visibly if it passes through a text-mode transfer.
Header layout, byte by byte
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 8 | PNG signature | Always 89 50 4E 47 0D 0A 1A 0A. The high bit of the first byte is set so a 7-bit transfer strips it visibly; bytes 1-3 spell PNG; the CR LF pair, the DOS end-of-file 1A and the trailing LF exist purely so a file mangled by a text-mode transfer fails loudly instead of silently. |
| 8 | 4 | IHDR chunk length | Big-endian byte count of the IHDR data, always 00 00 00 0D — 13 bytes. Every PNG chunk is length, type, data, CRC in that order, and IHDR must be the first one. |
| 12 | 4 | IHDR chunk type | The four ASCII letters IHDR. Chunk-type casing carries meaning: an uppercase first letter marks the chunk critical, so a decoder that does not understand it must reject the file rather than skip past it. |
| 16 | 4 | Width | Image width in pixels, big-endian unsigned 32-bit. Zero is illegal and the spec caps the value at 2^31 - 1. A tool reporting absurd dimensions is almost always reading these four bytes little-endian. |
| 20 | 4 | Height | Image height in pixels, encoded exactly like the width. Together with offset 16 this is the only place a PNG states its size — there is no second copy anywhere to cross-check against. |
| 24 | 1 | Bit depth | Bits per sample: 1, 2, 4, 8 or 16. Not every depth is legal with every colour type — indexed images stop at 8, and the two alpha types start at 8. |
| 25 | 1 | Colour type | 0 greyscale, 2 truecolour, 3 indexed (requires a PLTE chunk), 4 greyscale plus alpha, 6 truecolour plus alpha. This is the byte to read when a PNG 'lost its transparency': it says 2 where it used to say 6. |
| 26 | 1 | Compression method | Always 0, meaning deflate with a sliding window of at most 32768 bytes. No second method has ever been registered, so any other value means the header is damaged. |
| 27 | 1 | Filter method | Always 0, the set of five adaptive per-scanline filters. Which filter each row actually uses is a byte inside the compressed stream, not out here in the header. |
| 28 | 1 | Interlace method | 0 for none, 1 for Adam7. Adam7 lets a viewer paint a coarse version of the image early at a cost of a few percent in size; almost nothing produces it today. |
| 29 | 4 | IHDR CRC-32 | CRC-32 over the chunk type and the chunk data, but not over the length field. Change any byte from offset 12 through 28 and this stops matching, which is how a hex editor catches a hand-edited header. |
| 33 | variable | First chunk after IHDR | The next length-and-type pair. Usually IDAT, or first one of PLTE, tRNS, gAMA, sRGB, iCCP, pHYs, eXIf or acTL — the colour and metadata chunks that have to precede the pixel data. |
| -12 | 12 | IEND trailer | Every intact PNG ends with the same twelve bytes: 00 00 00 00 49 45 4E 44 AE 42 60 82, a zero-length IEND chunk plus its constant CRC. If those are not the final bytes, the file is truncated. |
Telling it apart from its neighbours
| Easily confused with | How to tell |
|---|---|
| APNG | An animated PNG is byte-identical for the first 33 bytes — same signature, same IHDR. The difference is an acTL animation-control chunk, which the spec requires before the first IDAT, so search the first few hundred bytes for 61 63 54 4C. A decoder that ignores acTL renders only the still first frame, which is exactly the intended fallback. |
| ICO | A modern .ico can store whole PNG images inside it, so a hex dump shows the PNG signature — just not at offset 0. An ICO opens with 00 00 01 00 and then a directory whose entries give each image's offset; the PNG signature sits at one of those offsets. Check offset 0 before concluding you have a PNG. |
| JPEG | Nothing subtle: FF D8 FF against 89 50 4E 47. It matters anyway, because 'Save as PNG' in most editors re-encodes a JPEG's already-lossy pixels rather than converting anything, and because screenshots renamed to .jpg keep their PNG bytes and still open everywhere. |
| WebP | Both handle lossless data with alpha and both are common screenshot output. WebP is a RIFF file: 52 49 46 46 at offset 0, a four-byte little-endian length, then 57 45 42 50 at offset 8. There is no PNG signature anywhere inside it. |
How these files break
- Text-mode transfer. Old FTP clients and a few CI artefact steps translate line endings, so the 0D 0A at offsets 4-5 collapses to a bare 0A, the whole file shifts by one byte and every chunk CRC after that point fails. The signature was designed to catch precisely this.
- Truncated download. The signature and IHDR are intact, so the dimensions still read correctly and a viewer paints the top of the image before falling off into grey or transparent rows where the IDAT stream ran out. The tell is a missing IEND in the last twelve bytes.
- A single flipped byte inside a chunk. libpng refuses the file on the CRC mismatch while browsers usually render it anyway, so the same PNG 'works' in Chrome and fails in a build script. Recomputing each chunk CRC tells you which one moved.
- Prepended junk. A stray UTF-8 BOM, an HTML error page or a PHP warning emitted before the image body pushes the signature off offset 0. Every byte of the image is still there; the fix is deleting everything ahead of 89 50 4E 47.
- Colour type quietly rewritten. A pipeline that re-encodes at colour type 2 instead of 6 drops the alpha channel. The result is a perfectly valid PNG with no transparency, and byte 25 is the only place in the file that admits it.
Where the format stands today
PNG is still the default for anything with hard edges or transparency: screenshots, UI assets, logos, diagrams, icons and anything destined for a README. For photographs it lost to JPEG decades ago and more recently to WebP and AVIF, which beat it badly on gradient-heavy images while keeping alpha. Where PNG remains first choice is anything that will be edited again, because it is lossless — a screenshot saved as PNG survives a dozen round trips through crops and annotations unchanged, while the same screenshot saved as JPEG visibly degrades every time. It has been supported by every browser since 1997, so unlike the newer formats it never needs a fallback.
Open PNG files on this site
Every one of these runs in your browser — the file never leaves your machine.
Related formats
Formats that are easy to confuse with PNG — compare their leading bytes.