Portable Network Graphics (PNG) is a standardized file format for storing and exchanging raster images: images represented as rectangular arrays of pixels. It uses lossless compression, so decoding reconstructs the stored image samples exactly rather than approximating them. PNG supports grayscale, indexed-color, and truecolor images; optional transparency; sample depths of up to 16 bits per color component; and information needed for consistent color reproduction. Its usual filename extension is .png, and its registered media type is image/png.
PNG was developed in 1995 as an openly specified alternative to GIF, particularly for the World Wide Web. Its combination of efficient compression, full-color transparency, and platform-independent structure made it important for screenshots, interface graphics, diagrams, illustrations, and image interchange. Later standardization incorporated animated PNG and additional facilities for modern color and high-dynamic-range imagery. The format’s central distinction is between exact storage of image samples and the interpretation of those samples: compression preserves their values, while color metadata, transparency rules, and display software determine their visible appearance.
Origins and standardization
PNG emerged from a practical problem in early web publishing. GIF was widely supported, but its image compression used the Lempel–Ziv–Welch algorithm, or LZW, which was subject to patents. Licensing announcements involving Unisys and CompuServe in late 1994 prompted developers to seek an alternative that could be implemented without dependence on that compression technology. Discussion began in January 1995 among contributors communicating over the Internet. Thomas Boutell helped initiate and coordinate the project, while a wider group developed the file structure, compression choices, and supporting software.
The project was not simply an attempt to reproduce GIF under a different name. GIF normally represents an image using a palette of no more than 256 colors and provides a transparent palette entry rather than continuously variable opacity. PNG incorporated truecolor images, grayscale images, higher sample precision, and an optional alpha channel. It also addressed practical interchange problems through a recognizable file signature, checksums, explicit byte ordering, and a mechanism for adding information without making older decoders unusable.
The World Wide Web Consortium published PNG 1.0 as a Recommendation on 1 October 1996. An Internet Engineering Task Force publication followed as RFC 2083 in March 1997. The specification subsequently developed through PNG 1.1 and 1.2. A second-edition W3C Recommendation appeared in 2003, and the format was also standardized internationally as ISO/IEC 15948:2004. These publications established the same basic architecture that remains recognizable in contemporary files: a signature, a sequence of typed chunks, filtered image samples, and a compressed image-data stream.
Early adoption depended partly on software support. Browsers and graphics programs did not all implement transparency and color handling consistently, so merely recognizing the format did not guarantee identical rendering. Support for partial transparency was especially important: once widely available, it allowed smooth translucent edges over arbitrary backgrounds without preparing separate images for each background color.
Animation followed a different path. The original PNG specification described a single image rather than a sequence of frames. Animated PNG, usually called APNG, was developed later and gained browser support before its integration into the PNG standard. The third edition, published as a W3C Recommendation in 2025, incorporated APNG and expanded the standardized treatment of color information. Consequently, the often-repeated statement that PNG cannot contain animation accurately describes the original specification, but not the full contemporary standard.
File signature and chunk architecture
A PNG file begins with the eight hexadecimal bytes 89 50 4E 47 0D 0A 1A 0A. This signature identifies the format and includes values chosen to expose certain forms of accidental text conversion or transmission damage. Following the signature is a sequence of chunks, each consisting of a four-byte data length, a four-byte type, the data itself, and a four-byte cyclic redundancy check. Lengths and other multibyte integers use big-endian order: the most significant byte appears first.
The chunk system is a central data structure of the format. A chunk’s type is a four-letter code such as IHDR or IDAT. The capitalization of particular letters conveys properties that an implementation can inspect without understanding the chunk’s contents. The first letter distinguishes critical chunks, which are necessary for correct interpretation, from ancillary chunks, which supply additional information. Other letters distinguish public from private types, reserve a bit for specification purposes, and indicate whether an unknown ancillary chunk can safely be copied after certain image modifications.
Every ordinary PNG image contains an IHDR chunk first, one or more IDAT chunks carrying compressed image data, and an IEND chunk last. IHDR has a fixed 13-byte payload specifying width, height, bit depth, color type, compression method, filter method, and interlace method. A PLTE palette chunk is required for indexed-color images and is optional for certain other color types. Chunk ordering is constrained: for example, a palette needed to interpret pixel indices must appear before the image data.
The payloads of consecutive IDAT chunks are concatenated to form one compressed stream. Chunk boundaries do not need to coincide with scanlines, compression blocks, or any other image boundary. This separation allows an encoder to emit data incrementally without knowing the final compressed size in advance. It also permits implementations to choose convenient chunk sizes without changing the decoded image.
Each chunk’s CRC covers its type and data, but not its length field. This detects many accidental changes to a file, although it does not authenticate the creator or prevent intentional modification. A correctly recalculated CRC can accompany malicious or misleading content.
The theoretical width and height limits are each pixels, but these are format limits rather than practical promises. Memory capacity, multiplication overflow, decompression limits, and application policies impose much smaller operational bounds. A decoder must therefore distinguish a dimension that is syntactically legal from an image it can safely allocate and process.
Color types, sample depths, and pixel representation
PNG defines five principal color types, identified by the numerical values 0, 2, 3, 4, and 6. Type 0 stores grayscale; type 2 stores red, green, and blue components; type 3 stores palette indices; type 4 stores grayscale plus alpha; and type 6 stores RGB plus alpha. These alternatives describe how image samples are organized, not how the file will necessarily appear on a particular display. Color-space information and transparency interpretation are separate parts of the format.
The permitted bit depths depend on the color type. Grayscale supports 1, 2, 4, 8, or 16 bits per sample. Indexed-color images support 1, 2, 4, or 8 bits per palette index. RGB, grayscale-with-alpha, and RGBA support 8 or 16 bits per sample. Thus an 8-bit RGBA image has four 8-bit components per pixel, conventionally described as 32 bits per pixel. A 16-bit RGB image has three 16-bit components and therefore uses 48 bits per pixel before filtering and compression.
Sub-byte samples are packed into bytes, beginning with the most significant bits. Sixteen-bit samples store their most significant byte first. These rules make the file representation independent of the native integer layout of a particular computer. Applications may convert that representation into another layout when loading an image—for example, into four 8-bit channels even when the file originally contained palette indices.
Indexed-color PNG uses a PLTE chunk containing RGB triplets. The palette has no more than 256 entries, and each entry uses 8 bits per red, green, and blue component, regardless of the index depth. An index depth of 4 bits can address at most 16 entries. The palette approach is especially effective for diagrams, icons, and illustrations that use relatively few distinct colors. However, converting a full-color image to a limited palette may alter colors even though the subsequent PNG compression is lossless.
This distinction is important when discussing fidelity. Lossless compression guarantees exact reconstruction of the samples submitted to the compression stage. It does not guarantee that an earlier export operation preserved the original image. Reducing 16-bit samples to 8 bits, quantizing colors, flattening transparency, or converting between color spaces can all change image information before the file is written.
PNG stores unsigned integer samples rather than general floating-point pixel values. Sixteen-bit storage provides 65,536 possible values per component, which can be useful during repeated tonal transformations and for images requiring fine gradations. It does not by itself specify a color gamut or dynamic range. Those properties depend on what the sample values mean, including the primaries and transfer function declared by the file or assumed by the application.
Scanline filtering and compression
PNG compression has two main stages: reversible filtering of scanlines, followed by compression of the resulting byte stream. The compression method uses DEFLATE inside a zlib wrapper. DEFLATE combines references to previously encountered byte sequences with Huffman coding. Unlike the transform and quantization process commonly associated with photographic JPEG, this pipeline does not discard image detail.
Filtering improves compression by expressing bytes in terms of nearby bytes that are often similar. Each scanline begins with a filter-type byte. The five defined filters are None, Sub, Up, Average, and Paeth. None leaves the scanline bytes unchanged. Sub subtracts the corresponding byte of the preceding pixel; Up subtracts the byte directly above; Average subtracts the integer average of the left and upper bytes. All these subtractions are performed modulo 256.
For a byte , let be the reconstructed byte to its left and the reconstructed byte above it. The Sub filter stores
while Average stores
Missing neighboring bytes at image boundaries are treated as zero. “Left” means a distance determined by the number of bytes per pixel, rounded up where necessary; filtering acts on bytes, not directly on complete multibyte sample values.
The Paeth filter, devised by Alan Paeth, also uses the upper-left byte . It computes , then selects whichever of , , or is closest to , using specified tie-breaking rules. The selected byte becomes the predictor. This is computationally inexpensive and often captures local changes in gradients and edges better than a single fixed predictor.
An encoder may choose a different filter for every scanline. A common heuristic selects the candidate with the smallest sum of absolute filtered-byte values when interpreted as signed quantities. This is only an approximation to the choice that produces the smallest final DEFLATE stream. More expensive encoders can test alternatives or optimize interactions between filtering and compression.
The compressed result depends strongly on image content. Large flat regions, repeated interface elements, and smooth predictable gradients often compress well. Noise, film grain, and irregular photographic texture usually compress less effectively. Encoder settings can substantially change file size and encoding time without changing decoded samples. PNG therefore has no intrinsic “quality level” corresponding to JPEG’s lossy quality control: a compression-level setting ordinarily changes the effort spent finding a compact representation, not the fidelity of the reconstructed image.
Transparency and alpha compositing
PNG supports both simple transparency declarations and per-pixel alpha. For indexed-color images, the tRNS chunk supplies alpha values associated with palette entries. Entries not covered by the chunk are fully opaque. Grayscale and truecolor images without an alpha channel can instead use tRNS to identify one sample value or one RGB triplet as fully transparent. These mechanisms differ from a full alpha channel, which can represent many degrees of opacity independently at every pixel.
Color types 4 and 6 include explicit alpha samples with the same bit depth as their color samples. Zero alpha denotes full transparency, and the maximum value denotes full opacity. Intermediate values represent partial coverage or opacity in compositing. This makes PNG suitable for antialiased text, shadows, translucent interface elements, and objects with smooth edges against backgrounds that are not known when the image is created.
PNG stores unassociated, also called straight, alpha. Its RGB or grayscale values are not multiplied by alpha in the file representation. In contrast, many rendering systems use premultiplied alpha internally because it simplifies compositing and interpolation. A decoder or graphics pipeline must convert between these representations correctly. Multiplying or dividing at the wrong stage can produce dark fringes, bright halos, or unstable colors near almost-transparent pixels.
For a foreground color , an opaque background color , and normalized foreground alpha , the basic “over” operation is
This equation assumes that the color values are expressed in a suitable linear-light space. Applying it directly to nonlinear encoded values can produce visibly different results, especially around soft edges and high-contrast transitions. Alpha itself represents linear opacity or coverage rather than a gamma-encoded color component.
Fully transparent pixels can still contain RGB values. Those values are invisible in a straightforward composite, but can matter when an image is resampled, filtered, edited, or converted between straight and premultiplied representations. Two PNG files may therefore look identical over every ordinary background while containing different underlying sample data. Removing invisible RGB information can reduce file size, but it is not a sample-preserving operation.
The optional bKGD chunk suggests a background color for circumstances where an application needs one; it does not replace alpha or force a particular compositing background. Likewise, an image viewer’s checkerboard is an interface convention, not part of the PNG image. Accurate handling requires keeping the stored foreground, transparency information, and eventual display background conceptually separate.
Color management and high-dynamic-range interpretation
An RGB triplet does not uniquely identify a visible color without additional assumptions. The result depends on the red, green, and blue primaries, the white point, and the relation between encoded sample values and light. PNG provides several mechanisms for recording this information. They are essential when an image moves between displays, editing applications, print workflows, and other systems with different color characteristics.
The gAMA chunk records an image gamma value as an integer scaled by 100,000. The cHRM chunk records the chromaticities of the white point and primary colors. Together, these can describe important aspects of a conventional RGB encoding, although a single gamma value does not reproduce every possible transfer curve. For example, the transfer function of sRGB is piecewise rather than an exact power law.
The sRGB chunk explicitly identifies the standard sRGB color space and includes a rendering-intent value. Another mechanism, iCCP, embeds a compressed ICC profile, enabling more general color descriptions and transformations. These chunks are not merely decorative labels: a color-managed application may use them to convert image values into the display’s color space. The specification defines relationships and precedence rules so that conflicting color declarations are not treated as equally authoritative alternatives.
A related chunk, sBIT, records how many source bits were significant before samples were scaled to a PNG-supported depth. For example, data originating with fewer meaningful component bits may be stored in an 8-bit or 16-bit representation. sBIT describes source precision; it does not define the transfer function, primaries, or brightness of the image.
Modern PNG specifications also provide standardized signaling relevant to high-dynamic-range imagery. The cICP chunk identifies color primaries, transfer characteristics, matrix coefficients, and range using established coded values. The mDCv and cLLi chunks carry mastering-display color-volume and content-light-level information. Such metadata can support images encoded with transfer characteristics intended for wider luminance ranges, but its presence does not ensure that every application will render the image as intended.
The distinction between storage precision and display interpretation remains fundamental. A 16-bit PNG can contain ordinary sRGB imagery, while high-dynamic-range interpretation requires appropriate encoding and signaling. Similarly, a wide-gamut image shown without color management may look oversaturated or otherwise incorrect even when every stored sample is decoded exactly. Consistent rendering therefore depends on the complete chain: valid metadata, correct precedence handling, supported color transforms, and a display pipeline capable of representing the intended result.
Text, metadata, and extensibility
PNG can store information beyond pixel values. Three text chunks serve different purposes. tEXt holds uncompressed text using the format’s Latin-1 text conventions. zTXt provides compressed text. iTXt supports international text encoded in UTF-8, along with fields for a language tag and a translated keyword. These mechanisms can carry descriptions, authorship information, copyright statements, software identifiers, and application-specific annotations.
Textual metadata is organized around keywords rather than a single universal document schema. Consequently, two applications may preserve the same chunk without agreeing on the meaning of its contents. Some programs use international text chunks to carry XMP packets, providing a structured metadata representation within PNG’s broader container architecture. The file format can transport such information without requiring every PNG decoder to interpret its internal vocabulary.
Other ancillary chunks have narrowly defined roles. pHYs records intended pixel dimensions or pixel aspect ratio, optionally in pixels per metre. This can influence physical-size interpretation in layout software, but it does not increase the number of pixels or add image detail. tIME records an image’s last modification time in Coordinated Universal Time; it is not necessarily the date of photography or original creation. The eXIf chunk carries Exif metadata, which can include information associated with image capture and processing.
Metadata preservation raises a distinction between an image editor and a simple viewer. A viewer can ignore many unknown ancillary chunks and still display the image. An editor that changes pixel data must decide whether unknown metadata remains valid. PNG’s safe-to-copy property helps make that decision: some unknown ancillary chunks may be retained after image changes, while others should be discarded because their meaning could depend on the original image.
This extensibility is controlled rather than unrestricted. Critical chunks cannot be silently ignored when their interpretation is unknown, and registered public chunk types have defined semantics. Private chunks allow specialized applications to exchange additional information without claiming that all PNG implementations understand it. Ordering constraints also matter; an otherwise well-formed metadata chunk can still be invalid if placed where the specification does not allow it.
Metadata affects privacy, reproducibility, and file comparison. Two visually identical images may differ in author fields, timestamps, profiles, or application-specific payloads. Conversely, stripping all metadata can remove information necessary for correct color rendering. A byte-for-byte comparison therefore answers a different question from comparing decoded samples or rendered appearance. Archival and interchange systems often need to state explicitly which of those forms of equivalence they intend to preserve.
Interlacing, progressive display, and animation
PNG’s standard interlace method is Adam7, named for Adam M. Costello and its seven passes. Instead of storing complete rows in a simple top-to-bottom sequence, Adam7 divides the image into seven interleaved subimages. Early passes provide a sparse approximation across the image; later passes fill the remaining positions. A viewer receiving data progressively can therefore show the whole scene roughly before all its detail has arrived.
The seven passes begin at pixel offsets , , , , , , and , with progressively finer horizontal and vertical steps. Filtering is applied independently within each pass, treating the pass as its own reduced image. All passes are then represented within the compressed image-data stream. Adam7 does not store a separate thumbnail and does not produce independently downloadable resolution levels.
Interlacing generally adds processing complexity and can increase file size because it changes the byte patterns available to the compressor and introduces filtering overhead for the separate passes. Its practical benefit also depends on the delivery system and viewer: software that waits for the complete download before displaying anything gains little from it. Interlacing and animation are separate features; a static image may be interlaced without containing any temporal sequence.
Animated PNG adds frame sequencing through the acTL, fcTL, and fdAT chunks. The animation-control chunk declares the frame count and number of plays. Frame-control chunks specify frame dimensions, offsets, timing, disposal behavior, and blending behavior. Frame data uses PNG’s lossless image-coding machinery rather than a video codec’s interframe motion prediction.
APNG distinguishes the default image from the animation sequence. Depending on the placement of the first frame-control chunk, the default IDAT image can either be the animation’s first frame or a separate fallback image. A decoder that does not understand APNG can still display that default image, because the animation-related chunks are ancillary. This provides backward compatibility, although a fallback image does not necessarily convey the animation’s full content.
Frames may cover only part of the overall canvas. Disposal operations determine whether a frame remains, is cleared to transparent, or restores the previous canvas state before the next frame. Blending operations determine whether new pixels replace the target area or are composited over it. Frame delays are expressed as rational values using numerator and denominator fields. These controls make APNG suitable for lossless short animations and animated interface graphics, but not inherently as compact as formats designed for long, motion-rich video sequences.
Applications and relationships with other image formats
PNG is particularly effective for images whose visual meaning depends on exact edges and repeated colors. Screenshots, software interface elements, line drawings, charts, maps, and text-heavy graphics often contain large uniform regions and predictable transitions. Lossy compression can introduce ringing or block artifacts around such boundaries, whereas PNG preserves the submitted samples. Its alpha support also makes it useful for compositing assets over changing backgrounds in a web browser or graphics application.
Photographs present a different trade-off. A camera image often contains fine texture and noise that reduce lossless compression efficiency. JPEG can usually represent such material at a much smaller size by discarding information according to a perceptual model. Saving a JPEG-decoded photograph as PNG prevents further lossy changes during that particular encoding step, but does not recover detail already removed by JPEG compression. It commonly produces a larger file containing the same pre-existing artifacts.
Compared with GIF, PNG provides richer color representation, higher precision, and full alpha transparency. GIF remains historically associated with simple animation and broad legacy compatibility, while APNG supplies lossless animated PNG sequences. For static indexed-color images, neither format is guaranteed to be smaller in every case: dimensions, palette organization, encoder choices, and image patterns influence the result.
PNG is also distinct from Scalable Vector Graphics (SVG). SVG describes shapes, text, paths, and other objects that can often be rendered at multiple sizes without fixing every pixel in advance. PNG records a specific raster. Enlarging a PNG requires interpolation and cannot reveal vector geometry that was never stored. Conversely, raster imagery can represent complex pixel-level content directly, and PNG decoding does not require interpreting a general vector document.
Newer formats such as WebP and AVIF provide alternative combinations of lossy compression, lossless modes, transparency, animation, and color capabilities. Their relative efficiency depends on content and encoder configuration, while their processing costs and implementation requirements differ from PNG’s. PNG’s continuing role rests partly on its mature ecosystem, exact sample reconstruction, comparatively straightforward image model, and broad software support rather than on consistently producing the smallest file.
In image processing and machine learning, PNG is often used for segmentation masks, synthetic images, and other data where altered pixel values would be undesirable. Such workflows must nevertheless control decoding. Palette expansion, automatic color conversion, alpha removal, and bit-depth reduction can change the array delivered to an application even when the PNG compression itself is perfectly lossless. A label image treated as display color is not necessarily equivalent to the same image treated as numerical class identifiers.
Implementations, validation, and security
PNG is implemented in browsers, operating-system imaging frameworks, graphics editors, command-line tools, and scientific libraries. A prominent reference implementation is libpng, commonly used with zlib. The format does not prescribe a particular application programming interface: one library may return raw sample arrays, another may automatically expand palettes and transparency, and an operating-system framework may convert the image into a preferred display representation.
Decoding involves several distinct stages. Software parses chunks, checks structural constraints, decompresses image data, reverses scanline filters, unpacks samples, interprets palettes and transparency, and may perform color conversion or compositing. These stages need not all happen at once. Streaming implementations can process data as it arrives, although an Up, Average, or Paeth filter requires access to the preceding reconstructed scanline within the relevant image or interlace pass.
A valid checksum does not establish that an image is safe. The principal risks arise from implementation errors and resource consumption. Incorrect size calculations can cause integer overflow or buffer overflows. Highly compressible input can expand into a very large image, consuming memory and processing time. Animation adds further dimensions, including many frames, repeated compositing operations, and canvas-state storage. Compressed profiles and text chunks also create decompression work outside the main pixel stream.
Robust decoding therefore requires validation of dimensions, color-type combinations, chunk lengths, sequence rules, decompressed sizes, and allocation calculations. Applications often impose limits below the format’s theoretical maxima. Sandboxing can reduce the consequences of a decoder defect, while fuzz testing helps expose malformed-input cases that ordinary images do not exercise. A decoder’s willingness to tolerate a damaged file is separate from whether that file conforms to the standard.
Optimization tools commonly change filter selection, DEFLATE settings, chunk layout, palette ordering, or metadata while preserving some defined notion of image equivalence. That definition matters. Repacking IDAT chunks can preserve both samples and interpretation; removing a color profile may preserve samples but alter rendering; discarding RGB values under zero alpha may preserve an immediate composite but change later editing behavior. Claims of “lossless optimization” are therefore most precise when they identify what is being preserved.
Validation likewise has several levels. A file can have a correct signature and valid CRCs yet violate ordering rules or contain inconsistent compressed data. It can decode successfully while carrying contradictory metadata. It can render identically to another file while differing in hidden samples or ancillary information. Reliable interchange depends on distinguishing structural validity, successful decoding, sample identity, and appearance rather than treating them as one interchangeable property.