Key takeaways
- Lossy compression shrinks files by permanently discarding data that people are least likely to notice. The original cannot be restored from the compressed file.
- Lossless compression keeps every bit, so it is reversible but produces larger files.
- JPEG, lossy WebP, AVIF, H.264, MP3 and AAC are lossy. PNG, FLAC and ZIP are lossless.
- MDN describes WebP as an excellent choice and AVIF as a good choice for web images, both with much better compression than PNG or JPEG.
- In Cloudinary, q_auto and f_auto choose quality and format for each request.
Lossy compression reduces file size by permanently removing data that human eyes or ears are least likely to notice. The result is much smaller than the original, but the discarded data cannot be recovered from the compressed file, which is why lossy compression is also called irreversible compression.
What Is Lossy Compression?
Lossy compression is a way to shrink large files without completely losing usability. Its goal is to reconstruct files in a way where you will not notice the missing data. It is typically employed when it is acceptable to lose some data, or when there is a need to free up storage space, and it is particularly relevant where very small file sizes are prioritised and slight quality degradation is acceptable.
The advantages include very small file sizes and broad support across tools, plugins, and software. The significant disadvantage is quality degradation at higher compression ratios. Once a file is compressed using lossy methods, the original version cannot be recovered, which is a critical consideration for data preservation.
Lossy compression is used in digital photography and video because it is faster than lossless compression. For example, MP3 files, a common format for audio compression, can be as small as one-tenth the size of lossless files. That reduction illustrates the effectiveness of lossy compression despite the potential for quality reduction.
How does lossy compression work?
- Transform. The encoder converts the data into a form that separates fine detail from broad structure, for example a frequency transform for images.
- Quantize. It rounds or drops the least noticeable detail. This step is where information is lost, and a stronger compression setting removes more.
- Encode. It packs the remaining values with lossless entropy coding.
Lossless Compression vs. Lossy Compression: What Is The Difference?
| Aspect | Lossy | Lossless |
|---|---|---|
| Data | Some data is discarded permanently | All data is kept |
| Reversible | No | Yes |
| File size | Much smaller | Larger |
| Quality | Drops as compression rises and can show artifacts | Identical to the original |
| Image formats | JPEG, lossy WebP, AVIF, JPEG XL | PNG, lossless WebP, lossless AVIF, lossless JPEG XL |
| Video and audio | H.264, HEVC, VP9, AV1, MP3, AAC, Opus | FLAC, ALAC |
| Best for | Photos, video, streaming audio and web delivery | Archives, logos, screenshots and editing masters |
Lossless compression is reversible, meaning the original data can be recovered exactly from its compressed form, as with ZIP files. Lossy compression is irreversible. The main structural difference is that lossy compression removes some data from a file to make it smaller, while lossless eliminates repetitive patterns and leaves everything else intact.
What are common lossy compression artifacts?
- Blocking: visible squares at high compression.
- Banding: stepped bands in smooth gradients such as skies.
- Ringing: halos around sharp edges and text.
- Generation loss: quality that falls each time a lossy file is saved again.
When should you use lossy or lossless compression?
- Use lossy for photos and video delivered to people on the web, where small files improve load time.
- Use lossless for master files, graphics with sharp text or flat colour, and anything you will edit again.
- Keep the original. Store a lossless or high quality master and generate lossy copies for delivery, so you never re-compress an already compressed file.
Which lossy image format should you choose for the web?
| Format | Compression | Browser support (MDN) | Notes |
|---|---|---|---|
| JPEG | Good for photos | All major browsers | Universal fallback, no transparency |
| WebP | Much better than JPEG and PNG | Chrome, Edge, Firefox, Opera, Safari | Supports transparency and animation |
| AVIF | Slightly better than WebP | Chrome, Edge, Firefox, Opera, Safari | Provide fallbacks |
| JPEG XL | Lossy and lossless, with HDR and progressive decoding | Chrome, Edge, Firefox, Safari; not yet universal | Provide a fallback |
Common mistakes with lossy compression
- Re-compressing an already lossy file.
Each save compounds artifacts. Always export from the master, not from a delivered copy. - Using lossy for logos, screenshots and sharp text.
Ringing shows most on hard edges. Those belong in a lossless format. - Picking one quality number for everything.
The right setting depends on the image. Automatic per-image quality beats a fixed value. - Serving one format to every browser.
JPEG to a browser that accepts AVIF leaves a large saving on the table. - Compressing before resizing.
Scale to the delivered dimensions first, then compress, or you pay twice.
Which platforms handle compression for you?
Most teams do not tune encoders per asset. The practical question is which platform decides quality and format per request.
| Platform | How compression is decided | Notable for |
|---|---|---|
| Cloudinary | q_auto chooses quality per image, f_auto chooses format per browser |
One API covering images and video, with upload, transformation and delivery together |
| Imgix | URL parameters with automatic format and compression options | Real-time image processing for large catalogs |
| ImageKit | Automatic format and quality with a built-in CDN | Straightforward setup for existing storage |
| Cloudflare Images | Automatic format negotiation on Cloudflare’s network | Bundled delivery for sites already on Cloudflare |
| Akamai Image & Video Manager | Policy-driven optimization at the edge | Enterprise delivery at scale |
How do you set lossy quality in Cloudinary?
Cloudinary’s automatic quality (q_auto) applies the best balance of visual quality and file size, and automatic format (f_auto) delivers each image in the optimal format for the requesting browser.
Cloudinary recommends adding both to every delivery URL as separate components, separated by a slash and not a comma. Use a level such as q_auto:eco when you prefer smaller files over quality.
https://res.cloudinary.com/<cloud_name>/image/upload/q_auto/f_auto/<public_id>
AVIF limits to know: Cloudinary documents that images converted to AVIF use additional quota and that images above 30 megapixels cannot be encoded to AVIF. Scale large images down first.
Optimized assets are then served over multi-CDN delivery, so viewers reach a nearby edge, and private media can be restricted with signed URLs carrying an expiry and with token-based access. Assets are encrypted with AES-256 at rest and TLS in transit.
Frequently asked questions
What is lossy compression?
Lossy compression shrinks a file by permanently discarding data that is least likely to be noticed. The smaller file cannot be turned back into the original.
Is lossy compression bad?
No. Lossy compression is why web images and streaming video are practical. It becomes a problem only when the setting is too aggressive or when files are re-compressed repeatedly.
Can you reverse lossy compression?
No. The discarded data is gone. Keep an original or lossless master if you may need the full quality later.
What is generation loss?
Generation loss is the quality lost each time a lossy file is decoded and saved again. Edit from the original and export once.
What is the best lossy format for web images?
According to MDN, WebP and AVIF compress better than JPEG and PNG, and JPEG remains the universal fallback. Automatic format selection picks the best supported format for each browser.
Check Out Our Tools That You May Find Useful:
