1. Home
  2. Guides
  3. How Compression Works

How image compression
actually works.

A 6 MB photo becomes 400 KB and looks the same. That isn’t magic — it’s four clever steps, and each one is understandable.

100% private — no uploads Free forever Batch & ZIP Works offline

Start with the problem: raw pixels are enormous

An uncompressed image stores three bytes (red, green, blue) per pixel. A 12 MP photo is therefore 36 MB raw. Yet the JPG your camera writes is ~3 MB and a well-compressed web copy is ~400 KB — a 90× reduction. Compression finds and removes two kinds of waste: redundancy (patterns that can be described more compactly) and irrelevance (detail your eyes can't see anyway).

Step 1: exploit how weak your color vision is

The encoder first converts RGB into one brightness channel (luma) and two color channels (chroma). Reason: human vision is sharp for brightness and blurry for color. So JPG keeps luma at full resolution and stores chroma at half resolution in each direction — an instant 50% saving before compression even begins, and you have never noticed it in any photo you've ever seen.

Step 2: the DCT — turning pixels into frequencies

The image is cut into 8×8 pixel blocks, and each block passes through the Discrete Cosine Transform, which re-describes those 64 pixels as a recipe of 64 wave patterns: one number for the block's average, then coefficients for progressively finer detail. Nothing is lost yet — it's the same information in a form where "smooth stuff" and "fine detail" sit in separate slots.

Why bother? Because in real photos, most blocks are mostly smooth: the fine-detail slots hold values near zero. The transform concentrates the image's energy into a few numbers — setting up the kill shot.

Step 3: quantization — where quality is decided

Now the lossy part. Each frequency coefficient is divided by a step size and rounded to the nearest integer. Fine-detail coefficients get divided by large steps, so most round to exactly zero. This rounding is the entire quality dial: quality 85 uses gentle steps (tiny, invisible rounding), quality 40 uses brutal ones (visible blocky artifacts). The discarded precision is gone forever — this is the "loss" in lossy.

Step 4: entropy coding — free compression on top

After quantization, blocks are mostly runs of zeros with a few significant numbers. Classic lossless tricks — run-length encoding and Huffman coding (frequent values get short codes) — pack this sparse data into very few bytes. This stage loses nothing; it's pure packing.

StageLossy?Contribution
Chroma subsamplingYes (imperceptible)~2× before anything else
DCTNo — reorganizes onlyConcentrates energy for step 3
QuantizationYes — the quality dialThe bulk of the savings
Entropy codingNoFinal ~2–3× packing

Modern formats: same skeleton, sharper tools

WebP, HEIC and AVIF keep the pipeline but upgrade each stage with video-codec technology: flexible block sizes instead of fixed 8×8, prediction (encoding only the difference from a guessed block), and arithmetic coding. Each generation buys roughly 25–50% over its predecessor — the details of when to use which are in Best image format for websites.

See it live: drop a photo into the JPG compressor and move the quality slider — you are directly controlling the quantization step above.

FAQ

Frequently asked questions

How can a file shrink 90% and look the same?

Because most of a photo’s data is either redundant (compressible patterns) or imperceptible (fine detail and color precision your eyes can’t resolve). Compression removes both; what remains is what you actually see.

What causes JPG artifacts and blockiness?

Aggressive quantization. At low quality settings, the rounding in each 8×8 block becomes coarse enough to see — block edges stop matching and ringing appears around sharp lines.

Why do screenshots compress badly as JPG?

Text and UI edges are high-frequency data — exactly what quantization attacks first. Formats with lossless or smarter modes (PNG, WebP) handle them far better.

Is the quality slider linear?

No. Between 100 and 85 file size drops steeply with almost no visible change; below ~60 quality falls fast while savings flatten. That is why 80–85 is the universal sweet spot.

Keep going

Related tools & guides