Skip to content
universalImage Compressor

Blog

Lossy vs Lossless Image Compression

The choice between lossy and lossless decides how small a file can get and whether it can be restored exactly.

By the Universal Image Compressor Team

The core difference

Lossless compression makes a file smaller without changing a single pixel. If you save an image losslessly, close it and open it again, the picture is identical to the original, down to the last value of every pixel. Lossy compression gives up that guarantee. It stores an approximation that looks very similar to the original, and the information that was dropped cannot be recovered afterwards.

The price of the guarantee is size. Lossless files of photographs are typically several times larger than lossy ones, because natural photos contain a lot of fine, noisy detail that does not compress well without being simplified. For images with flat colors and sharp edges, such as logos and screenshots, the gap is much smaller and lossless is often the better choice.

How lossless compression works

Lossless encoders look for patterns and write them more compactly. PNG, for example, first applies filters that predict each pixel from its neighbors and stores only the difference, and then compresses the result with the DEFLATE algorithm, the same family of methods used in ZIP files. The more repetitive the image, the better this works: a screenshot with large blank areas shrinks a lot, a noisy photograph hardly at all.

Because nothing is discarded, there is no quality setting that trades detail for size. Tools can only try harder to find patterns, which takes more time and gives modest gains. This is why re-saving a PNG usually does not make it much smaller, and why a compressor may report that the original is already optimized.

How lossy compression works

A lossy encoder such as JPEG transforms small blocks of the picture into a description of frequencies, from smooth gradients to fine detail. It then stores the strong, visible parts accurately and the weak, fine parts coarsely or not at all. Color information is often stored at a lower resolution than brightness, because the eye is less sensitive to it. The quality setting controls how coarse the stored values are.

The result is a much smaller file. At moderate settings the loss is hard to notice at normal viewing size. At very low settings, typical artifacts appear: visible blocks, smeared edges, halos around text and banding in smooth gradients. These artifacts are the visual cost of the savings, and they show where the limit of a given picture is.

Which formats are which

JPEG is lossy. PNG and GIF are lossless, although GIF is limited to 256 colors per frame. WebP and AVIF are flexible: both can be used in lossy or in lossless mode. According to Google, lossy WebP images are 25 to 34 percent smaller than comparable JPEG images at the same measured quality, and lossless WebP images are 26 percent smaller than PNG. Results vary with the picture, so treat these as typical values and not as a promise.

A file extension therefore does not always tell you whether the picture was compressed with loss. A WebP can be either, and a PNG that was made from a JPEG contains the JPEG's artifacts, now stored losslessly. Converting a lossy picture to a lossless format does not bring the lost detail back; it only makes the file bigger.

Generation loss

Every time you open a lossy file, edit it and save it again as a lossy file, new errors are added on top of the old ones. This is called generation loss. After many rounds, a picture can look noticeably worse, even if each single step used a high quality. Screenshots of screenshots and photos that have been shared and downloaded again and again show this effect clearly.

The simple rule is to keep an original in a lossless or high-quality form and to produce each lossy copy from that original, once. If you only have a compressed copy, avoid compressing it harder unless you must, because you start with errors that the encoder will treat as detail.

Choosing the right type

For photographs that people will only look at, lossy is the right choice: JPEG for the widest compatibility and WebP or AVIF for smaller files on modern websites. For screenshots, user interface graphics, diagrams, logos and anything with text, use a lossless format, or lossy settings with a high quality, because lossy artifacts show up most around sharp edges and letters.

For images that you will edit again, keep a lossless master. Edit that, and export lossy copies at the end. For images with transparency, PNG and lossless WebP preserve it exactly, and lossy WebP can store transparency too, usually at a much smaller size than PNG when some loss of quality is acceptable.

Trying it yourself

The best way to understand the difference is to try it. Add a photo and a screenshot to the compressor, set a moderate quality and compare the sizes. The photo will shrink a lot as a JPEG or WebP, while the screenshot may shrink only a little, or stay as it is if it is a PNG. Then lower the quality step by step and zoom in on text or edges to see where artifacts begin.

Because the compression runs on your own device, you can test as often as you like, with no upload and no waiting. Use what you see to pick the lowest quality that still looks right for the size at which the image will be displayed.

Compare file sizes at different quality settings with the free image compressor.

Open the image compressor