Two fundamentally different approaches
Lossless compression shrinks the file while keeping every pixel identical. Decoding returns exactly the original image. Lossy compression discards detail the human eye is unlikely to notice — subtle colour differences, high-frequency noise — and cannot be reversed.
Which format for which job
- JPEG — lossy, ideal for photographs. Very small files at quality 70–85, no transparency.
- PNG — lossless, ideal for screenshots, logos, icons and anything with sharp edges or transparency. Photographs stored as PNG are often 5–10× larger than needed.
- WebP — supports both lossy and lossless modes plus transparency, and is typically 25–35% smaller than JPEG at comparable quality. Supported by all current browsers.
- AVIF — the most efficient of the four, especially at low quality settings, but slower to encode and with less consistent support in older software.
Resize before you compress
Compression cannot fix an oversized image. A 4000-pixel-wide photo displayed in a 800-pixel column wastes bandwidth no matter how aggressively it is encoded. Resize to the largest size the layout can actually show (and add a 2× variant for high-density screens), then compress.
Choosing a quality level
For photographs, quality 75–85 is usually indistinguishable from the original at normal viewing size and cuts file size dramatically. Below 60, gradients start to band and edges show block artefacts. For screenshots and text, lossy compression produces visible ringing around letters — keep those lossless.
Practical targets
- Hero images: under 200 KB
- In-article photos: under 100 KB
- Thumbnails and icons: under 20 KB
Privacy note
Photographs often carry EXIF metadata: camera model, timestamps and GPS coordinates. Re-encoding with a compressor typically removes it, which is why "compress before sharing" is also a privacy measure, not just a size optimisation.
What a compressor actually removes
Every image contains redundancy. Neighbouring pixels are often similar, large areas share one colour, and some values appear far more often than others. A codec removes that redundancy in three stages: a transform that concentrates detail into a few coefficients, quantisation that throws away the coefficients a human is unlikely to notice, and entropy coding that stores the remaining values in fewer bits. Lossless formats stop before quantisation, so the decoded pixels are exact; lossy formats perform the quantisation step and accept that the original can never be reconstructed. Understanding which stage a setting controls explains why one slider changes the file size so much and another changes visible quality only slightly.
How the common codecs differ
- JPEG — splits the image into 8×8 blocks, applies a discrete cosine transform and quantises each block. It also subsamples chroma by default (4:2:0), storing colour at half resolution because the eye is less sensitive to it than to brightness.
- PNG — predicts each pixel from its neighbours, then compresses the residual with DEFLATE. Filters and palette reduction can change the file size a lot while keeping the pixels identical.
- WebP — has two modes: a block-based lossy mode derived from VP8, and a lossless mode (VP8L) that uses prediction and colour transforms. One file can mix transparency with either mode.
- AVIF — built on AV1 intra-frame coding, with better prediction and larger transform blocks than the older codecs. It can also carry HDR and wide-gamut colour.
Quality numbers are not comparable across formats
A JPEG saved at quality 80 and a WebP saved at quality 80 do not look the same, and neither matches an AVIF at 80. Each encoder maps its own scale onto different quantisation strengths, and some tools use 1–100 while others use 0–100 with a different default. Comparing numbers across formats is therefore meaningless; compare the decoded images and the file sizes instead.
Format comparison
| Format | Compression | Transparency | Typical use |
|---|---|---|---|
| JPEG | Lossy | No | Photographs, older content pipelines |
| PNG | Lossless | Yes | Screenshots, logos, UI assets |
| WebP | Both | Yes | General web delivery, best all-round support |
| AVIF | Both, mainly lossy | Yes | Size-critical pages where encoding time is acceptable |
Edge cases that decide the format
- Text in an image — screenshots, charts and UI mockups show ringing around letters under lossy compression. Keep them lossless or use a high quality setting and inspect the result.
- Sharp geometric logos — lossy codecs blur edges; SVG is the better answer when the asset is genuinely vector.
- Smooth gradients — low quality settings produce visible banding, especially in skies and soft backgrounds.
- Transparency — JPEG cannot store it; use PNG, WebP or AVIF instead of flattening the image onto white.
- Colour profiles — a wide-gamut photo converted to sRGB may shift visibly; check that the workflow converts the profile rather than discarding it.
- EXIF orientation — some tools rotate the image on load and others do not, producing a sideways result after re-encoding.
Generation loss and repeat compression
Every lossy re-encode discards a little more detail. A photo that passes through three tools at quality 70 looks noticeably softer than the same photo encoded once at the same setting. Keep an original master and generate the web version from it; never compress the compressed file. When a pipeline must resize and compress, resize first from the master and encode once.
How to judge whether the result is good enough
Metrics such as PSNR, SSIM and VMAF give a number, but numbers do not answer the only question that matters: can a visitor see the difference at the size the image is displayed? Zoom to 100% on a desktop screen, then check the actual layout size on a phone. Problems that are invisible when zoomed out become obvious when enlarged, and problems visible only when enlarged often do not matter at all. Compare side by side when in doubt, and prefer the smaller file when the two are indistinguishable.
Checklist for a web image pipeline
- Resize to the largest rendered size, plus a 2× variant for high-density screens.
- Photographs go to JPEG, WebP or AVIF; text and UI go to PNG or lossless WebP.
- Start at quality 80 for photos and lower it only if the comparison shows no visible loss.
- Encode once from the master file; never re-compress an already processed image.
- Strip metadata unless you specifically need it, and keep orientation consistent.
- Serve the right variant per browser with
pictureandsrcset, not one huge fallback. - Record the resulting file size per page so a future asset cannot silently regress it.
See also resize vs crop for choosing dimensions, and image format conversion for switching formats without losing quality. The Image Compressor applies these steps in the browser, and the Image Converter handles format changes when you need a specific output type.