How image compression actually works

Lossy vs lossless, quality settings, format-specific behavior, when compression breaks down — image compression explained without the math, but with practical guidance.

Image compression is one of those topics where everyone uses the tools but few people understand what they actually do. You drag a slider, the file gets smaller, and somehow the picture still looks fine. How?

This article explains compression without diving into the math. By the end you'll understand what's happening when you save a JPG at quality 80, why PNG compresses some images well and others poorly, and how to pick the right settings for your use case.

The fundamental insight

Image compression works because real-world images aren't random. They contain patterns. Pixels near each other tend to be similar colors. Sharp transitions are relatively rare. Some color combinations appear more often than others. Repeating data can be encoded more compactly.

Every compression algorithm exploits these patterns differently. Some are lossless — they find more efficient ways to store the same exact data. Others are lossy — they throw away some data based on what human eyes don't notice.

Lossless compression

Lossless compression makes files smaller without losing any information. Decompressing gives you back exactly the original bytes. This is the only acceptable approach when every pixel must be preserved exactly — medical imaging, technical diagrams, archival storage.

PNG uses lossless compression. So does the lossless mode of WebP. So do file formats like TIFF (with appropriate encoding).

The savings from lossless compression depend heavily on the content:

  • Graphics with flat colors compress very well (often 5-10× smaller than uncompressed).
  • Screenshots compress well (lots of repeated patterns).
  • Photographs compress poorly with lossless algorithms — typically only 2-3× smaller, because photos have lots of subtle variation that's hard to encode efficiently without throwing away data.

Lossy compression

Lossy compression throws away some data to achieve dramatic size reduction. The trick is throwing away the right data — the parts that human vision is bad at noticing.

JPG is the most famous lossy format. It works by:

  1. Converting to YCbCr color space (luminance + two chrominance channels). Human vision is more sensitive to brightness than color.
  2. Subsampling the chrominance. Color information is stored at lower resolution than brightness, because we don't notice.
  3. Breaking the image into 8×8 blocks and converting each to frequency components (DCT — Discrete Cosine Transform).
  4. Quantizing the high-frequency components — basically rounding them, throwing away precision. High-frequency components are subtle details we mostly don't notice.
  5. Encoding the result with lossless entropy coding.

The "quality" slider in JPG controls step 4 — how aggressively the high frequencies are quantized. At quality 100, almost nothing is lost. At quality 50, a lot is lost (and you can see the artifacts).

What "quality" actually means

The quality slider is misleading. It's not a percentage of how much quality is preserved — it's an index into a quantization table. The actual relationship between the number and the visible quality is non-linear and format-dependent.

Practical rules of thumb:

  • Quality 100 = visually identical to source, but file is much larger than needed.
  • Quality 90-95 = archival quality, minimal but real compression.
  • Quality 80-85 = the sweet spot. Almost everyone can't tell the difference from quality 100, but files are dramatically smaller.
  • Quality 70-80 = subtle artifacts on close inspection. Fine for thumbnails and content images.
  • Quality 60-70 = visible artifacts. Use only when bandwidth is critical.
  • Below 60 = obvious quality loss.

If you're not sure, use 85. It works for 95% of use cases.

Why compression artifacts look the way they do

When you crank quality way down, you see specific artifacts. These aren't random — they're consequences of how the compression algorithm works.

  • Blocking (8×8 squares becoming visible) — comes from the 8×8 DCT blocks JPG processes.
  • Ringing (halos around sharp edges) — comes from aggressive quantization of high-frequency components near edges.
  • Color banding (gradients becoming stepped) — comes from subsampling and quantization removing subtle color variation.
  • Color bleeding (red text becoming pink) — comes from chrominance subsampling.

WebP and AVIF have different artifact patterns because they use different (smarter) compression techniques. Modern formats produce more graceful degradation at low qualities — instead of blocks, you get softer, blurrier images.

When compression breaks down

Lossy compression has cases where it fails badly:

  • Sharp text on flat backgrounds. JPG smears edges. Use PNG or lossless WebP.
  • Pure gradients. Banding becomes visible. Use lossless or higher quality.
  • Images that have been compressed before. Re-compressing introduces compounding errors. Always work from originals.
  • Very small images. The overhead of compression metadata can exceed the savings.

Format-specific optimal settings

JPG

Quality 85 for most uses. 95 for archival. Below 70 only if file size is critical.

WebP (lossy)

Quality 80-85. WebP looks slightly better than JPG at the same quality setting because its compression is smarter.

AVIF

Quality 60-75 produces files comparable to JPG quality 85. AVIF's quality scale doesn't map directly to JPG's.

PNG

No quality setting (lossless). You can choose the compression level (0-9) which trades encode time for file size — but the output is bit-identical regardless. Level 6 is the usual default.

WebP (lossless)

Like PNG, but typically 25-50% smaller for the same content.

Compression vs resizing

If your image is 4000 pixels wide but will only be displayed at 800 pixels, resizing produces more savings than compressing. Resize first, then compress. Doing both gives you the smallest files.

The practical workflow

  1. Start with the best source you have (RAW, PNG, or high-quality JPG from the original capture).
  2. Resize to your needed dimensions — usually display size × 2 for retina.
  3. Pick the right format for the use case (WebP for web, JPG for compatibility, PNG for graphics).
  4. Set quality to 85 as your default.
  5. Compare visually if quality is critical. Adjust the slider until you find your acceptable point.
  6. Keep the original. You can always re-compress; you can never recover what compression discards.

This is the workflow most professional image pipelines follow. Now you can do the same.


Try it yourself with pictoolkit's compression tool — adjust the quality slider and see the file size and visual difference in real time.

Keep reading

Related articles