PNG Format: Is It Truly Lossless?

Understanding PNG Compression and Losslessness
The Portable Network Graphics (PNG) format is widely recognized as a lossless image format. However, users often encounter a setting for compression level during the saving process.
This prompts a valid question: if PNG is truly lossless, why does compression exist, and does its use compromise image quality?
The Role of Compression in PNG Files
PNG employs compression to reduce file size without discarding any image data. It's important to understand that compression, in this context, is different from the lossy compression used in formats like JPEG.
Lossless compression identifies and eliminates statistical redundancy within the image data. This is achieved through algorithms that represent repeating patterns more efficiently.
How PNG Compression Works
PNG utilizes the Deflate compression algorithm, the same one used by ZIP files. Deflate doesn't remove image information; it simply repackages it in a more compact way.
Higher compression levels result in smaller file sizes, but require more processing power to compress and decompress the image.
Lossless vs. Lossy Compression: A Key Distinction
Lossy compression, conversely, achieves greater file size reduction by permanently removing some image data deemed less important. This results in a loss of image quality.
PNG's compression is entirely lossless. Regardless of the compression level selected, the decompressed image will be identical to the original.
SuperUser and Community-Driven Q&A
This clarification comes from SuperUser, a valuable resource within the Stack Exchange network. Stack Exchange is a collection of question-and-answer websites built and maintained by a community of users.
SuperUser specifically focuses on expert answers to questions related to computer technology and software.
In Summary
The presence of compression settings in the PNG format does not negate its lossless nature. Compression is a method for reducing file size without sacrificing image quality.
Choosing a higher compression level simply increases the efficiency of data storage, not the removal of data itself.
PNG Compression and Image Quality
A SuperUser user, pkout, has inquired about the impact of compression levels on the quality of PNG images.
The question arises from the observation that image editors, like Gimp, offer compression level settings ranging from 0 to 9 when saving images in the PNG format.
Understanding PNG Lossless Compression
Despite the presence of a compression parameter, PNG remains a lossless image format.
This means that no visual information is discarded during the compression process, regardless of the level selected.
How Compression Level Affects PNG Files
The compression level in PNG doesn't influence the visual fidelity of the image.
Instead, it controls the trade-off between file size and compression time.
- Higher Compression Levels (e.g., 9): Result in smaller file sizes but require more processing time to compress.
- Lower Compression Levels (e.g., 0): Lead to larger file sizes but compress much faster.
Visual Precision and Lossless Behavior
The visual precision of the compressed image remains consistent across all compression levels.
You achieve lossless behavior at any compression setting, from 0 to 9.
The difference lies solely in how efficiently the image data is packed into the file.
In Summary
Choosing a compression level in PNG does not compromise image quality.
The optimal level depends on your priorities: smaller file size (level 9) or faster compression (level 0).
The core principle of lossless compression is maintained throughout the entire range of available settings.
Understanding PNG Compression
Contributors LordNeckbeard and jjlin from SuperUser provide insight into the nature of PNG compression. Let's examine their explanations.
LordNeckbeard's Explanation
PNG employs compression that is lossless. This means no image data is discarded during the compression process. The level of compression applied represents a balance between the resulting file size and the speed at which the image can be encoded and decoded. Similar concepts are found even in non-image formats, such as FLAC.
Identical Decoded Output Despite Compression Levels. Although varying compression levels result in different file sizes, the final, decoded image remains unchanged. The MD5 hashes of the decoded outputs can be compared using tools like ffmpeg with the MD5 muxer to verify this.
Demonstrating PNG Creation

- By default, ffmpeg utilizes a compression level of 100 when generating PNG files.
- A test revealed that level 100, representing maximum compression, required approximately three times longer for encoding and five times longer for decoding compared to level 0, the lowest compression setting.
File Size Comparison

Verifying Decoded Output with MD5 Hashes

The identical MD5 hashes confirm that the decoded images, or the uncompressed raw files, are precisely the same, regardless of the compression level used.
jjlin's Perspective
PNG is inherently a lossless format. The terminology used in programs like GIMP may not always be the most precise.
The compression level can be understood as the quality of compression or simply the degree of compression applied. Lower compression results in larger files but faster processing times. Conversely, higher compression yields smaller files at the cost of increased processing time.
Diminishing returns are typical; the reduction in file size becomes less significant as compression levels increase, while the encoding time continues to grow. The optimal level is ultimately a matter of preference.
Do you have additional insights to share regarding this explanation? Please contribute in the comments section. For a more comprehensive discussion and further responses from other knowledgeable Stack Exchange users, visit the original discussion thread.