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.
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:
- Row filtering: Replaces raw pixel values with delta differences relative to preceding or upper pixels. Across flat color fields, delta values trend to zero.
- 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 type | PNG file size (1920 × 1080) | Structural reason |
|---|---|---|
| Application UI screenshot | ~180 KB | Repetitive solid backgrounds and identical font glyphs |
| Line illustration (limited palette) | ~40 KB | High spatial redundancy |
| Foliage photography | ~4.2 MB | Sensor noise prevents exact byte-level repetition |
| Photograph encoded as JPEG (quality 80) | ~290 KB | Quantization 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:
- Colour space conversion: Transforms RGB data into luminance and chrominance channels (YCbCr). Human vision detects brightness differences far more keenly than colour shifts.
- 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.
- Discrete transform: Applies discrete cosine transforms (DCT) or directional transform blocks to translate spatial pixel matrices into frequency coefficients.
- 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.
- 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.

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 count | Visual output state |
|---|---|
| 1 | Indistinguishable from raw source under normal viewing |
| 2 | Minimal perceptible shift |
| 5 | Edge softening across detailed textures |
| 10 | Noticeable block boundary artefacts in skies and shadows |
| 20 | Severe 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:
- Preserve a lossless master file. Keep master assets in PNG, TIFF, or RAW formats, and export lossy derivatives only for distribution.
- Consolidate edits before final export. Complete cropping, sharpening, and color grading before encoding to lossy formats.
- 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
-
Is the file a continuous-tone photograph intended for final distribution? Use lossy compression at quality 75–85.
-
Does the file contain text, UI elements, flat graphics, or transparency? Use lossless compression.
-
Is the file an intermediate asset that will undergo further editing? Use lossless compression.
-
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.
Tools covered in this article
Keep reading
- WebP vs AVIF vs JPEG: format selection in 2026A technical comparison of JPEG, WebP, and AVIF covering compression efficiency, encoding latency, container overhead, and browser support.6 September 2026 · 7 min read
- How to compress images with little visible quality loss: a practical guideWhy images are usually far bigger than they need to be, what the quality slider really controls, and a repeatable order of operations that works.6 September 2026 · 7 min read
- Why browser-based image processing is more private than any upload toolWhat happens when you upload an image to a free online tool, why in-browser processing offers a different guarantee, and where the boundary sits.6 September 2026 · 7 min read