Compresser
← Back to Blog

Image Compression Basics: Lossy and Lossless Explained

Compression removes redundancy, not dimensions by magic

An uncompressed image stores values for millions of pixels. Neighboring pixels are often similar, and viewers do not notice every tiny change equally. Compression exploits these patterns. Lossless methods describe the same data more efficiently; lossy methods also discard selected detail. These are fundamentally different bargains.

Lossy compression: transform and quantize

JPEG first changes RGB pixels into brightness and color components, then works on blocks of 8×8 pixels. A discrete cosine transform (DCT) expresses each block as low- and high-frequency patterns. Smooth regions need few high-frequency terms; fine texture and sharp edges need many.

Quantization divides those terms by values from a table and rounds them. Larger divisors discard more fine information, leaving more zeros that are cheap to encode. This step is irreversible. The JPEG quality setting influences those divisors; it is not a "percent of image retained" meter.

Chroma subsampling often stores color detail at lower resolution than brightness. Our eyes are generally more sensitive to luminance detail, so this can reduce size with modest visible change in photos. It is less forgiving on colored text and sharp UI edges, where colored fringes become obvious.

Lossless compression: prediction and repeated patterns

Lossless algorithms never change the decoded pixels. PNG predicts a pixel from its neighbors and stores the smaller difference; DEFLATE then efficiently encodes repeated byte sequences. GIF uses a palette and LZW coding. A run of identical or predictable colors is inexpensive, while a noisy photograph gives the encoder little repetition to exploit.

That is why a PNG screenshot with broad flat colors may compress well and a PNG photo may be several times larger than its JPEG counterpart. If you reduce a PNG to an indexed palette, you are changing colors even though the resulting PNG file is losslessly encoded. The palette step and the file encoding should not be confused.

Why JPEG suits photos and PNG suits sharp graphics

Image Likely choice Reason
Portrait or landscape JPEG or WebP Continuous tones tolerate careful lossy encoding
UI screenshot with text PNG or lossless WebP Thin strokes need clean edges
Logo with transparency SVG, PNG, or WebP Preserve shapes and alpha
Animated illustration Animated WebP or GIF Compare compatibility and frame detail

JPEG can create blocks, halos, and banding around precisely the details screenshots rely on. PNG preserves those details but cannot make a complex photo tiny without changing colors or dimensions. The format comparison covers when converting helps.

Choose a strategy for the destination

For an editable master, retain the original or a lossless version. For a web photo, start with a display-appropriate size and test JPEG or WebP around a moderate quality setting. For a strict email or form limit, resize first and then search for a quality that fits. For printing, retain enough pixels and avoid repeatedly re-encoding JPEG.

Output Starting point Critical check
Web photo JPEG or WebP around quality 75–85 Details at final display size
Small preview Smaller pixel dimensions Subject still readable
Screenshot PNG or lossless WebP Text and thin lines
Archival master Original or lossless copy No generation loss

The online image compressor exposes these principles through quality, color-count, and precision controls. Its comparison preview lets you inspect the same area before committing a result. See the complete tutorial for the workflow and target-size guide when you have a hard KB limit.

Three common misconceptions

  1. A higher JPEG setting restores an old file. Lost detail cannot be reconstructed by another encode.
  2. Lossless always means small. Lossless encoding cannot remove genuine complexity without changing pixels or dimensions.
  3. One quality number fits every image. Texture, noise, dimensions, and display context change the result. Measure the actual file and inspect the visible image.