compression · formats · fundamentals

Lossy vs lossless compression: technical differences and use cases

How lossless entropy encoding compares with lossy psychovisual quantization, how generational degradation compounds, and criteria for selecting image codecs.

The OpusImg teamUpdated 12 September 20267 min read

Lossless compression reduces file sizes while ensuring the decoded output matches the input bit for bit. Lossy compression achieves higher reduction ratios by permanently discarding high-frequency pixel data that falls below human visual perception thresholds.

Stated plainly: lossless gives back exactly what went in, lossy gives back something similar. Everything worth knowing follows from what "similar" means, how the similarity degrades when the process repeats, and which kind of image each approach was designed around.

Selecting between lossy and lossless methods depends on image content type, editing stages, and delivery constraints.

How lossless compression works

Lossless algorithms identify and compress repeated data patterns. Decompression inverts the operation completely, reconstructing the source byte sequence without alteration.

In simple run-length encoding, a row of forty white pixels is stored as a single count rather than forty distinct RGB values. Production formats implement more sophisticated algorithms:

PNG executes two passes in sequence:

  1. Row filtering: Replaces raw pixel values with delta differences relative to preceding or upper pixels. Across flat color fields, delta values trend to zero.
  2. DEFLATE encoding: Combines LZ77 string matching with Huffman coding to replace repeated byte patterns with compact bit references.

Because PNG relies on statistical repetition, it compresses interface screenshots and vector line art efficiently while failing to compress photographic captures:

Content typePNG file size (1920 × 1080)Structural reason
Application UI screenshot~180 KBRepetitive solid backgrounds and identical font glyphs
Line illustration (limited palette)~40 KBHigh spatial redundancy
Foliage photography~4.2 MBSensor noise prevents exact byte-level repetition
Photograph encoded as JPEG (quality 80)~290 KBQuantization sheds high-frequency noise

The same photograph as a quality-80 JPEG lands around fourteen times smaller than its PNG. A screenshot is full of exact repetition: thousands of identical background pixels, the same anti-aliased letterform recurring down a page, flat panels of interface colour. A photograph has almost none, because sensor noise means no two pixels that look identical actually are, and there is nothing for the encoder to reference.

Because photographic noise prevents exact pixel repetition, saving a raw photo as a PNG often produces a file larger than the raw raster data.

How lossy compression works

Lossy algorithms focus on psychovisual redundancy, identifying which spatial details human vision is least likely to detect.

Modern lossy formats (JPEG, lossy WebP, and AVIF) process raster data through standard transformation stages:

  1. Colour space conversion: Transforms RGB data into luminance and chrominance channels (YCbCr). Human vision detects brightness differences far more keenly than colour shifts.
  2. Chroma subsampling: Halves the resolution of the colour channels (4:2:0 subsampling), discarding half the colour information with minimal perceived loss on natural photographs.
  3. Discrete transform: Applies discrete cosine transforms (DCT) or directional transform blocks to translate spatial pixel matrices into frequency coefficients.
  4. Quantization: Divides high-frequency transform coefficients by values in a quantization matrix and rounds the results to integers. The user-facing quality slider scales this matrix.
  5. Entropy coding: Encodes the resulting quantized values using lossless Huffman or arithmetic coding.

Quantization removes high-frequency data permanently, and it is directed by a model of human vision. That is why a quality-80 photograph can be a fifth of the size with no visible difference: what the encoder discarded was disproportionately what the eye was least equipped to notice.

The assumption underneath that whole pipeline is that the image is a photograph. Applied to typography or a screenshot, every stage misfires. The "fine detail" step 4 rounds away is the crisp edge of the lettering, the colour subsampling in step 2 smears the boundary between two flat fills, and the block structure lands exactly where flat colour makes it most visible. The result is ringing artefacts (mosquito noise) along high-contrast boundaries.

The same compress tool on a scanned postage stamp, choosing lossless WebP and explaining that flat colours with transparency keep every edge crisp
The same tool and the same defaults, a different decision: flat colour with an alpha channel routes to lossless rather than a lossy encode.

Generational loss across editing pipelines

Lossless encoding can be repeated indefinitely without degradation. Re-saving a PNG multiple times leaves pixel values identical.

Lossy encoding degrades image fidelity with every save cycle. Each re-encode re-transforms previously quantized blocks, converting earlier compression artefacts into new noise patterns that require additional bit allocation.

An example sequence on a photograph saved at quality 80:

Generation countVisual output state
1Indistinguishable from raw source under normal viewing
2Minimal perceptible shift
5Edge softening across detailed textures
10Noticeable block boundary artefacts in skies and shadows
20Severe geometric distortion and color banding

Generational loss frequently accumulates unintentionally: a camera saves a photo as JPEG (gen 1), an editor crops and exports it (gen 2), a messaging application downsamples and re-compresses it (gen 3), a content management system processes it upon upload (gen 4), and a social distribution channel re-encodes it for delivery (gen 5). Nobody made a poor decision at any step, and no single step is visible in the result. The damage is cumulative and nothing in the file records how many passes produced it.

To prevent cascading compression damage:

  1. Preserve a lossless master file. Keep master assets in PNG, TIFF, or RAW formats, and export lossy derivatives only for distribution.
  2. Consolidate edits before final export. Complete cropping, sharpening, and color grading before encoding to lossy formats.
  3. Do not re-save lossy files at higher quality. Saving a quality-60 JPEG at quality 100 retains previous artefacts while inflating file size.

Format selection by asset type

Match encoding methods directly to image structure:

Use lossless compression for:

  • User interface screenshots, system captures, and software documentation.
  • Vector charts, diagrams, schematics, and line drawings.
  • Typography, logos, and iconography.
  • Assets requiring transparent alpha channels.
  • Archival masters and medical imagery where accuracy is mandatory.

Use lossy compression for:

  • Photographic content on websites, email templates, and mobile applications.
  • Ecommerce product imagery and lifestyle galleries.
  • High-resolution hero headers where bandwidth reduction is critical.

For hybrid imagery, such as screenshots containing embedded product photographs, test both lossless WebP and lossy WebP at quality 80 using an in-browser converter to compare file size against text sharpness. When styling screenshots with background padding and drop shadows via our screenshot beautifier, apply all layout effects before encoding the final asset.

Common compression misconceptions

Lossless does not imply high resolution. Lossless guarantees exact parity with the source file. Converting a heavily compressed, blurry JPEG into a PNG preserves the compression artefacts perfectly inside a substantially larger container.

Quality 100 is not lossless. Quality 100 in lossy codecs continues to run transform and quantization steps with minimal divisor values. It typically produces a file two to three times larger than quality 90 without adding visible detail.

PNG does not outrank JPEG on quality. PNG is lossless, which is a different property from being better. For a photograph, a quality-90 JPEG is visually indistinguishable from the PNG at roughly a tenth of the size. For a screenshot, the PNG is both smaller and visibly cleaner. The two formats are matched to content types rather than ranked against each other.

Format name does not define compression type. Both WebP and AVIF support distinct lossy and lossless operational modes. Specifying "WebP" requires choosing between its lossy DCT-based encoder and its lossless entropy engine, which is why "save it as WebP" is an incomplete instruction in any automated pipeline.

Selection checklist

  1. Is the file a continuous-tone photograph intended for final distribution? Use lossy compression at quality 75–85.

  2. Does the file contain text, UI elements, flat graphics, or transparency? Use lossless compression.

  3. Is the file an intermediate asset that will undergo further editing? Use lossless compression.

  4. Uncertain, usually because the frame mixes photography with text? Encode it both ways, compare at 100% zoom, and keep the smaller file that still looks right.

That fourth option is a two-second experiment rather than an evasion, and it answers the question for the specific image in front of you more reliably than any rule applied to content nobody has looked at. OpusImg's image compressor compiles WebAssembly codecs to execute both lossy and lossless algorithms locally inside client browser threads, eliminating server uploads, so testing three settings costs three seconds and sends nothing anywhere.

Why the distinction outlives each format

New codecs arrive every few years with better ratios at both ends of the range. The underlying trade does not move: information discarded cannot be recovered, and information kept costs bytes.

Better encoders shift the curve by discarding more intelligently, so a modern format at a given visual quality is smaller than an older one at the same quality. They do not remove the decision. AVIF ships a lossy mode and a lossless mode for the same reason JPEG and PNG divided the work thirty years ago, and choosing between them still depends on whether the image is a photograph and whether this is the final delivery.

We build the browser-based image tools this guide refers to, which is also how we know where they stop being the right answer.