Lossy vs Lossless Compression: How They Work and Differ
Lossy vs lossless compression explained: lossless rebuilds the exact original, lossy discards detail for smaller files. See which image formats use each type.
Updated
Lossless compression makes a file smaller without changing its contents: when you open it, you get back exactly what went in. Lossy compression makes a file much smaller by permanently discarding information people are unlikely to notice. PNG, GIF and ZIP are lossless. JPEG, and the usual modes of WebP and AVIF, are lossy.
This guide explains the mechanics. For a practical workflow with recommended settings, see how to compress images without losing quality.
How lossless compression works
Lossless compression finds redundancy and describes it more briefly. Nothing is removed, only rewritten. Three ideas do most of the work.
Repetition. Instead of storing the same thing many times, store it once and refer back to it. A row of 500 white pixels becomes the equivalent of "white, 500 times". Dictionary methods extend this to repeated patterns anywhere in the data.
Frequency. Values that occur often are given short codes and rare values long ones, the same principle as Morse code using a single dot for the letter E.
Prediction. For images, guess each pixel from its neighbors and store only the error. In a smooth area the errors are mostly zero or close to it, which the first two steps then compress very well.
PNG combines all three: a prediction filter on each row, followed by DEFLATE, the same algorithm used in ZIP files. Decoding reverses each step and the original pixels come back bit for bit.
The limit is the data itself. Flat, repetitive content such as screenshots, diagrams and logos compresses well. A photograph is full of sensor noise and fine texture, which is close to random, and random data has no redundancy to remove. Lossless compression of a typical photo often saves only around half.
How lossy compression works
Lossy compression changes the data so that it becomes easier to compress, choosing changes that human senses are poor at detecting. JPEG is the classic example and runs in four stages.
- Separate brightness from color. The image is converted from red, green and blue into one brightness channel and two color channels.
- Reduce color resolution. Eyes are much more sensitive to detail in brightness than in color, so the color channels are commonly stored at half resolution in each direction. This is called chroma subsampling.
- Transform into frequencies. Each block of 8 by 8 pixels is rewritten as a mix of patterns, from smooth gradients to fine checkerboard detail.
- Quantize. The amounts of fine-detail patterns are rounded off coarsely, and many become zero. This is where the information is lost, and it is what the quality slider controls.
The rounded result is then compressed losslessly. Because so many values are now zero, it packs down far more than the original pixels could. A photo can typically be reduced to about a tenth of its raw size before the damage becomes noticeable.
WebP and AVIF follow the same outline with newer techniques borrowed from video codecs, which is why they reach the same visual quality in fewer bytes.
Lossy vs lossless side by side
| Lossless | Lossy | |
|---|---|---|
| Original recoverable | Yes, exactly | No |
| Typical photo size | Large | Small |
| Quality setting | None needed | Yes |
| Repeated saving | No effect | Damage accumulates |
| Sharp edges and text | Perfect | Can show artifacts |
| Best for | Graphics, screenshots, source files, data | Photos, audio and video for delivery |
Which formats are which
| Format | Type | Notes |
|---|---|---|
| JPEG | Lossy | A lossless variant exists in the standard but is almost never used |
| PNG | Lossless | Always |
| GIF | Lossless, with a catch | Limited to 256 colors, so converting a photo to GIF loses color first |
| WebP | Both | Separate lossy and lossless modes |
| AVIF | Both | Usually used in lossy mode |
| HEIC | Lossy | As produced by phone cameras |
| TIFF | Usually lossless | A container that can hold uncompressed, lossless or JPEG data |
| BMP | Usually uncompressed | Large files with no compression at all |
| SVG | Not applicable | Vector text, not pixels |
The same split exists outside images. MP3 and AAC are lossy audio, FLAC is lossless audio. Common video formats such as H.264 are lossy. ZIP and gzip are lossless, which is why they are safe for documents and code, where a single changed bit would be an error.
What the quality setting means
The quality number in a lossy encoder, usually 1 to 100, controls how coarse the rounding in the quantization step is. Three things are worth knowing.
It is not a percentage. Quality 80 does not mean 80 percent of the information is kept or that the file is 80 percent of the original size. It is a position on a scale that the encoder defines.
It is not comparable across formats or tools. Quality 80 in JPEG, WebP and AVIF give different files and different visual results. Even two JPEG encoders can differ at the same number.
It is not linear. The first steps down from 100 remove a large share of the bytes with almost no visible change. Near the bottom of the scale, each step saves little and costs a lot.
Quality 100 in a lossy format is still lossy. To keep every pixel, use a lossless format.
Generation loss
Every lossy save runs the discard step again. Open a JPEG, make a small edit, save, and repeat: artifacts from each round are treated as real detail by the next, and the image slowly degrades. This is called generation loss.
The rules that follow from it:
- Keep an original, in a lossless format or straight from the camera.
- Do all editing on the original and export the lossy version once, at the end.
- Converting between lossy formats, such as JPG to WebP, is also a new lossy generation. Convert from the original where possible.
- Saving a lossy image in a lossless format stops further loss but restores nothing.
Choosing between them
Use lossless when the content has hard edges, text or flat color, when the file is a master copy you will edit again, or when exact values matter, as in medical, scientific or pixel art images.
Use lossy when the content is photographic and the file is for delivery: web pages, email, social media. The size difference is large, the visible difference at sensible settings is not. The format-by-format choice is covered in JPEG vs PNG and image file formats.
Seeing the difference yourself
The Image Compressor makes both kinds visible. With JPEG, WebP or AVIF selected as the output, the quality slider is a lossy control, and the before and after preview lets you drag across the image to find the point where artifacts appear. With PNG selected, the output is lossless: the slider then changes only how hard the tool works to shrink the file, and the pixels stay identical.
To move a batch of JPG or PNG files to lossy WebP, the WebP Converter shows the saving per file.
Try it
Drop a photo into the Image Compressor, choose JPEG and pull the quality down to 20 to see what lossy artifacts look like. Bring it back up until they vanish, then switch the format to PNG and compare the file size of the lossless version.