PNG (Portable Network Graphics)
| Full name | Portable Network Graphics |
|---|---|
| Extensions | .png, .apng (animated) |
| MIME type | image/png, image/apng |
| Type | raster image, lossless compression |
| Starts with | 89 50 4E 47 0D 0A 1A 0A (\x89PNG\r\n\x1a\n) |
| Specification | PNG Third Edition (W3C Recommendation) |
| Also standardized as | ISO/IEC 15948 |
| Maintained by | W3C (PNG Working Group) |
| License | open, royalty-free |
PNG stores raster images without losing quality. It supports grayscale, RGB and palette images, 1 to 16 bits per channel and a full alpha channel for transparency. It’s the standard format for screenshots, UI graphics, icons, diagrams and any image with sharp edges or text. For photographs JPEG, WebP or AVIF give much smaller files.
Animated PNG (APNG) adds frames to a regular PNG file. Programs that don’t support APNG show the first frame. APNG is part of the PNG Third Edition specification and works in all current web browsers.
When to use PNG#
- Use for screenshots, logos, icons, line art, charts and images with text: lossless compression keeps edges sharp.
- Use when you need transparency with soft edges (8-bit alpha channel).
- Use as an intermediate format when editing, to avoid quality loss on every save.
- Avoid for photos on the web: a photo in PNG is often 5-10 times larger than a good-quality JPEG, WebP or AVIF.
- Avoid when you need lossy compression or very large images: use WebP, AVIF or JPEG XL instead.
File structure#
A PNG file is an 8-byte signature followed by a sequence of chunks.
89 50 4E 47 0D 0A 1A 0A signature
00 00 00 0D chunk length: 13
49 48 44 52 chunk type: IHDR
00 00 01 00 00 00 00 C8 width 256, height 200
08 06 00 00 00 bit depth 8, color type 6 (RGBA), compression, filter, interlace
xx xx xx xx CRC-32
... more chunks: IDAT (image data), IEND (end)
The signature bytes detect common transfer errors: the high-bit byte 0x89 catches 7-bit transfer, \r\n and \n catch line-ending conversion, 0x1A stops output of the file with type on DOS.
Chunks#
Each chunk has 4 parts. All integers in PNG are big-endian.
| Field | Size | Description |
|---|---|---|
| Length | 4 bytes | size of the data field (not counting type and CRC) |
| Type | 4 bytes | ASCII letters, e.g. IHDR |
| Data | Length bytes | chunk contents |
| CRC | 4 bytes | CRC-32 of type and data |
The case of the letters in the type carries meaning: an uppercase first letter means the chunk is critical (a decoder must understand it), lowercase means ancillary (can be skipped). A lowercase fourth letter means the chunk is safe to copy by editors that don’t understand it.
Critical chunks:
| Chunk | Purpose |
|---|---|
IHDR |
header: width, height, bit depth, color type, compression method, filter method, interlace method. Must be first |
PLTE |
palette of up to 256 RGB entries. Required for color type 3 |
IDAT |
compressed image data. Can be split across many consecutive IDAT chunks |
IEND |
marks the end of the file. Empty |
Common ancillary chunks:
| Chunk | Purpose |
|---|---|
tRNS |
transparency: alpha for palette entries, or a single transparent color |
gAMA, cHRM, sRGB, iCCP |
color space: gamma, chromaticities, sRGB intent, embedded ICC profile |
cICP, mDCV, cLLI |
HDR and wide color gamut (Third Edition) |
tEXt, zTXt, iTXt |
text: Latin-1, compressed and UTF-8 key/value pairs (e.g. Title, Author, Software) |
eXIf |
Exif metadata |
pHYs |
physical pixel size (DPI) |
tIME |
last modification time |
bKGD, sBIT, hIST, sPLT |
background color, significant bits, palette histogram, suggested palette |
acTL, fcTL, fdAT |
APNG animation control, frame control and frame data |
Color types and bit depths#
| Color type | Name | Channels | Allowed bit depths |
|---|---|---|---|
| 0 | grayscale | 1 | 1, 2, 4, 8, 16 |
| 2 | truecolor (RGB) | 3 | 8, 16 |
| 3 | indexed (palette) | 1 | 1, 2, 4, 8 |
| 4 | grayscale + alpha | 2 | 8, 16 |
| 6 | truecolor + alpha (RGBA) | 4 | 8, 16 |
Width and height are 4-byte values from 1 to 231-1.
Compression#
Image data is compressed in 2 steps:
- Filtering: each scanline (row) gets a filter type byte, one of None, Sub, Up, Average or Paeth. A filter replaces each byte with the difference from a prediction based on the pixel to the left, above, or both. This makes the data more compressible. Encoders usually pick the filter per row.
- DEFLATE: the filtered rows are compressed with zlib (DEFLATE, the same as in ZIP and gzip) and the zlib stream is split into IDAT chunks.
Optional Adam7 interlacing stores the image in 7 passes so a browser can show a coarse preview before the whole file is downloaded. Interlaced files are usually larger.
Making PNG files smaller#
- Use a palette (color type 3) when the image has 256 colors or fewer. Lossy quantizers like pngquant turn RGBA images into palette images with alpha, often cutting the size by 60-80%.
- Re-compress with a better DEFLATE encoder: oxipng, OptiPNG, ECT or zopflipng try many filter and compression settings and keep the smallest result, without changing pixels.
- Remove metadata chunks you don’t need (
tEXt,iTXt,eXIf,iCCP). - Don’t use interlacing.
Specifications and documentation#
- PNG Specification, Third Edition (W3C Recommendation, 2025): the current specification, including APNG, HDR (
cICP) andeXIf - PNG Specification, Second Edition (W3C, 2003), the same as ISO/IEC 15948:2004
- libpng.org PNG home page: specifications, extensions, tools
- Extensions to the PNG specification: registered ancillary chunks
- PngSuite: official test images for decoders
- PNG on Wikipedia
Software that opens PNG files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; also opens PNG inside archives and comic books | |||
| Web browsers | ✓ | ✓ | ✓ | ✓ | view | Chrome, Edge, Firefox, Safari; APNG animation too. Also on Android and iOS |
| Microsoft Photos | ✓ | view, edit | built into Windows | |||
| Paint | ✓ | view, edit, create | built into Windows | |||
| macOS Preview | ✓ | view, edit, convert | built into macOS | |||
| GIMP | ✓ | ✓ | ✓ | view, edit, create, convert | free, open source | |
| Krita | ✓ | ✓ | ✓ | view, edit, create | free, open source | |
| Paint.NET | ✓ | view, edit, create, convert | free | |||
| Adobe Photoshop | ✓ | ✓ | view, edit, create, convert | commercial | ||
| IrfanView | ✓ | view, convert | free for non-commercial use | |||
| XnView MP | ✓ | ✓ | ✓ | view, convert | free for private use | |
| ImageMagick | ✓ | ✓ | ✓ | convert, create | command line, open source | |
| Photopea | ✓ | view, edit, create, convert | free, runs in the browser | |||
| Squoosh | ✓ | convert | optimize and convert in the browser | |||
| oxipng | ✓ | ✓ | ✓ | convert | lossless PNG optimizer, command line | |
| pngquant | ✓ | ✓ | ✓ | convert | lossy palette compression, command line |
Libraries#
Open-source libraries that read and write PNG. See all PNG libraries for a comparison.