What Is Image Compression?
An uncompressed image stores color values for every single pixel. A 12-megapixel photo at 24-bit color occupies 36 MB of raw data. That is impractical for web pages, email, and storage, so we compress images to reduce file size. The fundamental question is: are you willing to lose some data in exchange for dramatically smaller files?
The answer splits all image compression into two families. Lossy compression permanently discards information that the algorithm considers less important to human perception. Lossless compression rearranges and encodes data more efficiently without discarding anything. Both produce smaller files, but the trade-offs are fundamentally different.
Lossy Compression — Smaller Files, Some Data Lost
Lossy compression works by exploiting the limitations of human vision. Our eyes are far more sensitive to changes in brightness than to changes in color, and we struggle to perceive fine high-frequency detail. Lossy algorithms take advantage of these blind spots to discard data that most viewers will never miss.
How JPEG lossy compression works
JPEG, the most common lossy format, compresses images through a multi-step pipeline:
- Color space conversion: The image is converted from RGB to YCbCr, separating brightness (luma) from color (chroma). This allows the algorithm to treat each channel differently.
- Chroma subsampling: The color channels are downsampled (typically 4:2:0), reducing color resolution by 75%. Because human vision has low chroma sensitivity, the reduction is nearly invisible.
- DCT (Discrete Cosine Transform): The image is divided into 8×8 pixel blocks, and each block is transformed from spatial pixel values into frequency coefficients. Low-frequency coefficients represent smooth gradients; high-frequency coefficients represent fine detail and edges.
- Quantization: This is where data is permanently lost. High-frequency coefficients are divided by large numbers and rounded, effectively zeroing out fine detail. The quality setting (Q1–Q100) controls how aggressively this rounding occurs.
- Entropy coding: The quantized coefficients are further compressed using Huffman coding or arithmetic coding, producing the final compact bitstream.
The result: a 36 MB raw image becomes a 2–4 MB JPEG at quality 85, a reduction of 10:1 to 18:1, with quality that most viewers cannot distinguish from the original.
Lossy image formats
| Format | Year | Typical ratio | Notes |
|---|---|---|---|
| JPEG | 1992 | 10:1 – 50:1 | Universal support, no transparency, DCT-based |
| WebP (lossy) | 2010 | 12:1 – 60:1 | 25–34% smaller than JPEG, supports transparency |
| AVIF (lossy) | 2019 | 15:1 – 80:1 | ~50% smaller than JPEG, HDR, 10/12-bit color |
| HEIC | 2015 | 12:1 – 60:1 | Apple default, HEVC-based, limited non-Apple support |
When to use lossy compression
- Photographs — Natural images with smooth gradients, complex textures, and millions of colors. JPEG artifacts are nearly invisible in photographic content.
- Web images — Page speed is critical for user experience and SEO. Lossy compression delivers the smallest possible files.
- Social media — Platforms re-compress uploads anyway (Instagram uses Q75, Facebook uses Q85). Starting with a well-optimized JPEG minimizes double-compression artifacts.
- Email attachments — Most email providers cap attachment sizes at 25 MB. Lossy compression keeps photo batches within limits.
- Mobile apps — Bandwidth is limited and expensive on cellular networks. Smaller images mean faster load times and lower data usage.
Lossless Compression — Perfect Quality, Larger Files
Lossless compression reduces file size without discarding a single bit of image data. The decompressed output is mathematically identical to the original input, pixel for pixel, bit for bit. You can compress and decompress a million times and the image will never change.
How PNG lossless compression works
PNG, the most common lossless format, uses a two-stage compression pipeline:
- Prediction (filtering): Before compression, PNG applies one of five filter algorithms to each row of pixels. Each filter predicts the value of the current pixel based on neighboring pixels and stores only the difference (residual). For smooth areas, residuals are close to zero, which compresses very efficiently.
- DEFLATE compression: The filtered data is compressed using DEFLATE (the same algorithm behind ZIP and gzip). DEFLATE combines LZ77 dictionary matching (finding repeated byte sequences) with Huffman coding (assigning shorter codes to more frequent values).
Because no data is discarded, lossless compression ratios are modest. A typical photograph compresses to roughly 2:1 to 3:1. Simple graphics with large areas of flat color can achieve 10:1 to 50:1 because the prediction step produces long runs of zeros.
Lossless image formats
| Format | Year | Typical ratio | Notes |
|---|---|---|---|
| PNG | 1996 | 2:1 – 5:1 | Universal support, alpha transparency, web standard |
| WebP (lossless) | 2010 | 2.5:1 – 7:1 | ~26% smaller than PNG, alpha transparency |
| AVIF (lossless) | 2019 | 3:1 – 8:1 | Best lossless ratio, slow encoding, growing support |
| TIFF (LZW) | 1986 | 1.5:1 – 3:1 | Print/publishing standard, large files, no web support |
| GIF | 1987 | 3:1 – 10:1 | 256-color palette only, animation, legacy format |
| BMP | 1986 | 1:1 (none) | Uncompressed, huge files, Windows-only use |
When to use lossless compression
- Graphics, logos, and icons — Hard edges, flat colors, and text produce severe JPEG artifacts. PNG handles them perfectly with small file sizes.
- Screenshots — Screen captures contain text, UI elements, and sharp lines. PNG preserves them crisply; JPEG blurs them.
- Pixel art — Every pixel is intentionally placed. Lossy compression destroys the precise color boundaries that define the art style.
- Medical and scientific imaging — Diagnostic accuracy depends on exact pixel values. Lossy artifacts could mask or mimic pathology.
- Legal documents and scans — Evidentiary integrity requires bit-perfect reproduction. Lossy compression alters the original data.
- Archival storage — Preserving the original unaltered for future use, even if the current use case would tolerate lossy compression.
- Editing workflows — Working files should remain lossless. Export to lossy formats only as the final step.
Visual Comparison — Lossy vs Lossless Side by Side
The practical difference between lossy and lossless depends heavily on the image content and the quality setting. Here is what to expect at different JPEG quality levels compared to the lossless PNG original:
| Quality | File size (typical 12 MP photo) | Compression ratio | Visible artifacts |
|---|---|---|---|
| PNG (lossless) | 15–25 MB | ~2:1 | None — bit-perfect |
| JPEG Q95 | 5–8 MB | ~5:1 | Imperceptible without pixel-level comparison |
| JPEG Q85 | 2–4 MB | ~10:1 | Imperceptible at normal viewing distance |
| JPEG Q75 | 1–2 MB | ~20:1 | Slight softening, visible on zoom in gradients |
| JPEG Q50 | 400–800 KB | ~40:1 | Blocking, ringing around edges, color banding |
Where artifacts appear first in lossy compression:
- Sky and gradients — Smooth tonal transitions develop visible banding steps. This is the earliest and most common JPEG artifact.
- Sharp text and edges — High-contrast boundaries produce "ringing" or "mosquito noise" — halos of discolored pixels around crisp edges.
- Fine repetitive patterns — Fabric weaves, brick textures, and hair strands can develop moiré patterns or smearing.
- Areas of flat color — Subtle color shifts become visible when large areas should be perfectly uniform.
Key insight: For photographs, JPEG at quality 85 or above is visually indistinguishable from the lossless PNG original for the vast majority of viewers. The file size difference, however, is dramatic: 2–4 MB (JPEG Q85) vs 15–25 MB (PNG). That is a 5–10x reduction.
Generation Loss — The Cumulative Cost of Lossy Re-saves
One of the most important differences between lossy and lossless compression is what happens when you open, edit, and re-save a file multiple times. This is called generation loss, and it only affects lossy formats.
What happens during each JPEG re-save
Every time you open a JPEG, edit it (even slightly), and save it again as JPEG, the entire lossy compression pipeline runs again. The DCT transform, quantization, and rounding all repeat. Each cycle discards slightly different data, and the losses accumulate:
| Re-save count | JPEG Q90 | JPEG Q80 | JPEG Q60 |
|---|---|---|---|
| 1 (original save) | Imperceptible loss | Imperceptible loss | Slight softening |
| 3 re-saves | Still imperceptible | Faint artifacts on zoom | Visible degradation |
| 5 re-saves | Faint artifacts on zoom | Noticeable at normal view | Significant blocking |
| 10 re-saves | Noticeable softening | Heavy blocking | Severely degraded |
| PNG (any count) | Zero change — identical to original after any number of saves | ||
How to avoid generation loss
- Edit in lossless formats: Keep your working files as PNG, TIFF, or PSD. Only export to JPEG as the final step.
- Save once, save well: If you must work in JPEG (e.g., camera raw exports), choose quality 92+ for working copies and only save the final output at your target quality.
- Use non-destructive editors: Tools like Adobe Lightroom apply edits as metadata overlays — the original file is never re-compressed until export.
- Avoid screenshot-of-screenshot chains: Each capture re-compresses through the screen's display pipeline. Share original files instead.
Lossless formats have zero generation loss. You can open, edit, and save a PNG file a thousand times. The output will remain identical to what you intended. This is why professional photographers work in lossless formats and only export to JPEG for final delivery.
When File Size Matters More (Choose Lossy)
In many real-world scenarios, the cost of large files outweighs the benefit of pixel-perfect quality. Lossy compression is the right choice when:
- Web page speed: Google considers page load time a ranking factor. Images are typically the heaviest assets on a page. Converting a hero image from PNG (15 MB) to JPEG Q85 (3 MB) can cut load time by several seconds.
- Email size limits: Gmail caps attachments at 25 MB. A batch of 10 photos at PNG quality would exceed this immediately. As JPEGs, they fit comfortably.
- Social media uploads: Instagram, Facebook, Twitter, and TikTok all re-compress uploaded images. Starting with an already-compressed JPEG minimizes the double-compression penalty.
- Mobile bandwidth: On 3G/4G networks, every kilobyte counts. Lossy images load faster and consume less data.
- Cloud storage costs: Photo libraries of thousands of images can occupy hundreds of gigabytes as PNG. As JPEG, the same library fits in a fraction of the space.
- CDN bandwidth bills: Content delivery networks charge per byte transferred. Smaller images directly reduce hosting costs.
When Quality Matters More (Choose Lossless)
Some use cases demand that no data is lost, regardless of file size. Lossless compression is essential when:
- Medical imaging: X-rays, MRIs, and CT scans must preserve exact pixel values. Compression artifacts could mimic or mask pathological findings. The DICOM standard mandates lossless compression for diagnostic images.
- Legal and forensic documents: Court-admissible evidence must be provably unaltered. Lossy compression modifies the data, which could raise challenges to authenticity.
- Archival and cultural preservation: Museums and libraries digitize rare documents for long-term storage. The digital copy must be a faithful representation of the physical original, with no compression artifacts introduced.
- Print production: High-end printing workflows require uncompressed or losslessly compressed source files. JPEG artifacts can become visible when images are printed at high DPI on quality paper.
- Editing workflows: Every time you crop, color-correct, retouch, or composite in a lossy format, you lose additional data. Keeping source files lossless preserves maximum editing flexibility.
- Pixel art and retro graphics: The art form depends on exact pixel colors and boundaries. A single pixel shifted by lossy compression ruins the aesthetic.
- Screenshots and documentation: Technical documentation screenshots must show exact UI text and icons. JPEG artifacts make text blurry and hard to read.
The Middle Ground — "Visually Lossless"
Between mathematically perfect (PNG) and aggressively compressed (JPEG Q60) lies a practical sweet spot: visually lossless compression. This means technically lossy — some data is discarded — but the difference is imperceptible to the human eye under normal viewing conditions.
The JPEG sweet spot
For photographs, JPEG quality 85–92 is the visually lossless zone:
- Q90–92: Mathematically different from the original (SSIM ~0.98–0.99) but visually identical even under careful comparison. Files are roughly 3–5x smaller than PNG. Ideal for archival JPEG exports and high-quality web images.
- Q85–89: The most efficient sweet spot. Files are 5–10x smaller than PNG. No perceptible difference at normal viewing distances. This is what Google, Apple, and most web platforms recommend for optimized images.
- Q80–84: Still visually excellent for photographs. Minor artifacts may become visible on extreme zoom in gradients. The best balance for bandwidth-conscious web delivery.
Practical recommendation: For most users converting PNG photos to JPG, quality 85 is the ideal starting point. It delivers excellent visual quality with dramatic file size savings. Increase to 90–92 for images where fine detail is critical (e.g., product photography, portfolios). Drop to 80 only when minimizing file size is the top priority.
Why we cannot see the difference
The reason JPEG compression works so well is rooted in visual psychophysics. Human vision has specific, well-documented limitations that lossy algorithms exploit:
- Contrast sensitivity function (CSF): Our eyes are most sensitive to medium spatial frequencies (4–8 cycles per degree of visual angle). JPEG discards high-frequency detail that falls outside this peak sensitivity range.
- Chromatic resolution: Our color vision (driven by cones) has much lower resolution than our brightness vision (driven by rods). JPEG exploits this through chroma subsampling, halving color resolution with no perceptible effect.
- Masking: In areas of high texture and detail, our sensitivity to additional detail drops sharply. JPEG can compress textured regions more aggressively without visible artifacts.
Modern Formats — Lossy and Lossless in One
The distinction between "lossy format" and "lossless format" is becoming less relevant. The two most important modern image formats — WebP and AVIF — support both modes in a single container.
WebP: the versatile all-rounder
Developed by Google and released in 2010, WebP offers both lossy and lossless compression with alpha transparency support:
- Lossy WebP produces files 25–34% smaller than JPEG at equivalent visual quality. It uses VP8 video codec technology adapted for still images.
- Lossless WebP produces files ~26% smaller than PNG. It uses a custom algorithm with prediction, entropy coding, and color cache.
- Browser support: Over 96% of all browsers as of 2026, including Chrome, Firefox, Safari, and Edge.
# Create lossy WebP (replaces JPEG)
convert input.png -quality 85 -define webp:lossless=false output.webp
# Create lossless WebP (replaces PNG)
convert input.png -define webp:lossless=true output.webp
AVIF: next-generation efficiency
Based on the AV1 video codec, AVIF delivers the best compression ratios of any widely supported format:
- Lossy AVIF produces files ~50% smaller than JPEG. It handles gradients and low-contrast detail exceptionally well, avoiding the banding artifacts that plague JPEG.
- Lossless AVIF achieves better ratios than both PNG and lossless WebP, though encoding is significantly slower.
- Additional capabilities: HDR, 10-bit and 12-bit color depth, wide color gamut, film grain synthesis.
- Browser support: ~93% as of 2026, with Safari having added support in version 16.4. Still growing.
Choosing the right format in 2026
| Scenario | Recommended format | Why |
|---|---|---|
| Photos for web | WebP (lossy) or AVIF | Smallest files, broad support |
| Universal compatibility | JPEG Q85 | Works everywhere, including email and old devices |
| Graphics & transparency | WebP (lossless) or PNG | Perfect quality, alpha channel support |
| Archival/editing | PNG or TIFF | Universal lossless, no generation loss |
| Cutting-edge performance | AVIF + WebP fallback | Best compression but needs fallback chain |
Technical Reference — ImageMagick Commands
For developers and power users who need to convert between lossy and lossless formats from the command line, here are the essential ImageMagick commands:
# PNG to JPEG (lossless to lossy) — quality 85
convert input.png -quality 85 -strip output.jpg
# Maximum PNG compression (lossless, level 9)
convert input.png -strip -quality 95 PNG:output.png
# Lossy WebP from PNG
convert input.png -quality 85 -define webp:lossless=false output.webp
# Lossless WebP from PNG
convert input.png -define webp:lossless=true output.webp
# Compare SSIM (structural similarity) between original and compressed
compare -metric SSIM original.png compressed.jpg null: 2>&1
Note on PNG quality numbers: In ImageMagick, PNG "quality" is not a lossy quality setting. The tens digit (0–9) controls the DEFLATE compression level (9 = maximum compression, smallest file, slowest encoding). The ones digit selects the prediction filter strategy. Quality 95 means maximum compression with adaptive filtering — the smallest possible PNG with no quality loss.