learn

Lossy vs lossless compression

What lossy and lossless compression discard and keep, with examples in JPG, PNG, WebP, MP3, FLAC and video, and why re-compressing adds loss each time.

The difference

Lossless compression shrinks a file so that decoding gives back exactly the original bits, like a ZIP file. Lossy compression throws away detail that people are unlikely to notice, such as subtle color changes in a photo or very high frequencies in music, and gets much smaller files in return; what was discarded is gone for good. Choosing between them is a trade between size and fidelity, and the right answer depends on what the file is for and whether it will be edited again.

By type of media

MediaLosslessLossyTypical saving of lossy
ImagesPNG, WebP lossless, AVIF lossless, GIF (256 colors)JPG, WebP, AVIF, HEIC5 to 10 times smaller for photos
AudioFLAC, ALAC; WAV and AIFF are uncompressedMP3, AAC, Ogg Vorbis, OpusMP3 at 192 kbps is about 7 times smaller than CD-quality WAV
VideoFFV1, ProRes 4444 XQ (near-lossless)H.264, H.265, VP9, AV1essential: raw video is tens of GB per minute
DocumentsZIP, gzip, PDF text streamsimages inside a PDF can be JPGdepends on the content

Lossless compression works best on repetitive data (text, flat graphics); it cannot shrink a photo or a recording much, because they are full of noise that never repeats exactly.

Generation loss

Every time a lossy file is decoded and encoded again, a little more is lost, even at the same settings, and the artifacts of each round add up: blocks and halos in JPG, swirly "underwater" sound in MP3. Rules that avoid it:

  • Keep a lossless master (the camera RAW or a PNG, the WAV or FLAC, the project file) and export lossy copies from it.
  • Edit from the master, not from the last JPG or MP3.
  • Converting lossy to lossless (JPG to PNG, MP3 to WAV) stops further loss but never restores quality; the file just gets bigger.
  • Converting between two lossy formats (WebP to JPG, AAC to MP3) adds a generation: use a high quality setting.

Choosing in practice

FAQ

Is PNG always better quality than JPG?

PNG is exact, so it never adds artifacts, but a PNG made from a JPG keeps the JPG's artifacts. For photos, a good JPG looks the same and is much smaller.

Can I tell if a file was compressed with loss?

Not from the extension alone for WebP and AVIF, which have both modes. Signs of lossy compression are blocky areas, halos around edges and smeared fine detail.

Is WAV lossless compression?

WAV usually holds uncompressed PCM audio, so it is lossless but not compressed. FLAC is lossless and about half to two thirds of the size.

Does zipping a JPG or MP3 make it smaller?

Barely. They are already compressed, so a ZIP saves a few percent at most.