PNG is a format used for image files. It is lossless, meaning that it does not contain any errors or data that can be damaged or corrupted. PNG files are often used to store images on the internet, as they are very small and easy to load. Some people believe that PNG is not lossless because some of the data in a PNG file can be lost if the file is not stored properly. However, this argument does not hold up to scrutiny. First, if a PNG file is not stored properly, then it will likely be lost when the user deletes it or moves the file to another computer. Second, if some data in a PNG file is lost, then it can be recovered by using a software program that specializes in recovering lost files. Finally, even if some data in a PNG file is lost, there are ways to recover it without using software programs. For example, many people use online storage services to store their images. These services keep track of how many times an image has been downloaded and allow users to download any image they want without having to worry about losing any data.


The PNG format is supposed to be a lossless format, but when you save an image as a PNG file, you are asked to choose a compression level. Does this mean that the PNG format is actually not lossless after all? Today’s SuperUser Q&A post helps clear up the confusion for a curious reader.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

The Question

SuperUser reader pkout wants to know if the quality of a PNG image is affected by the compression level chosen:

Is there a difference in the quality of the image depending on the compression level you choose?

If it has a compression parameter that affects the visual precision of the compressed image, how is PNG lossless then? Can someone please explain this to me? Do I get lossless behavior only when I set the compression level to 9?

The Answer

SuperUser contributors LordNeckbeard and jjlin have the answer for us. First up, LordNeckbeard:

Followed by the answer from jjlin:

The compression level is a trade-off between file size and encoding/decoding speed. To overly generalize, even non-image formats such as FLAC have similar concepts.

Different Compression Levels, Same Decoded Output

Although the file sizes are different due the the different compression levels, the actual decoded output will be identical. You can compare the MD5 hashes of the decoded outputs with ffmpeg using the MD5 muxer. This is best shown with some examples.

Create PNG Files

By default, ffmpeg will use -compression_level 100 for PNG output. A quick, sloppy test showed that 100 (the highest compression level) took roughly three times longer to encode and five times longer to decode than 0 (the lowest compression level) in this example.

Compare File Size

Decode the PNG Files and Show MD5 Hashes

Since both hashes are the same, you can be assured that the decoded outputs (the uncompressed raw files) are exactly the same.

Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

Think of it as quality of compression or level of compression. With lower compression, you get a bigger file, but it takes less time to produce, whereas with higher compression, you get a smaller file that takes longer to produce.

Typically you get diminishing returns, i.e. not as much decrease in size compared to the increase in time it takes when going up to the highest compression levels, but it is up to you.