Image Compression Techniques: Lossy, Lossless, and Format Comparison

A practical guide to image compression: how JPEG, PNG, WebP, and AVIF work, lossy vs lossless, best use cases per format, and quality-size tradeoffs.
Related tool
Image Compressor

Reduce JPG, PNG and WebP photo size without uploading to a server. Runs in a local Web Worker.

Why image compression matters

Images dominate internet bandwidth — roughly 40–60% of the average web page by weight. A page that loads 4MB of unoptimized images instead of 400KB of well-compressed ones costs mobile users real data, slows down rendering, and hurts search ranking.

Good compression is never just "smaller is better." It is the point where quality is indistinguishable from the original at the intended viewing size, and every byte beyond that is waste.

Lossless compression

Lossless compression preserves every pixel exactly. Decompressing a lossless image returns a byte-for-byte identical copy of the input. The savings come from finding patterns — repeated regions, predictable gradients, color palettes — and encoding them compactly.

PNG (Portable Network Graphics) is the dominant lossless format for web use. It combines filtering (predicting each pixel from its neighbors) with DEFLATE compression. PNG excels on images with sharp edges, solid colors, or text — screenshots, icons, diagrams. It is a poor choice for photographs because natural photos lack the structure PNG exploits.

Lossy compression

Lossy compression discards visual information the human eye is less sensitive to, achieving compression ratios 5–20× higher than lossless. The catch is that decompression never perfectly reconstructs the original — it is an approximation.

JPEG (Joint Photographic Experts Group) is the classic lossy format. It converts an image into blocks, applies the discrete cosine transform (DCT), quantizes the high-frequency coefficients (where the eye is least sensitive), and entropy-codes the result. Quality settings (typically 1–100) control how aggressively coefficients are quantized.

Modern formats: WebP and AVIF

WebP, developed by Google and published in 2010, supports both lossy and lossless modes. Lossy WebP is typically 25–35% smaller than JPEG at equivalent visual quality. It also supports transparency (alpha channel), which JPEG cannot handle natively.

AVIF (AV1 Image File Format), standardized in 2019, is the current state of the art. It is based on the AV1 video codec and achieves 30–50% smaller files than JPEG at the same quality, with full alpha and HDR support. Browser support reached mainstream availability around 2023.

Choosing the right format

No single format is universally best. Match format to content and distribution:

  • Photographs, web delivery: AVIF (if clients support it) > WebP > JPEG
  • Screenshots, diagrams, icons: PNG (lossless) or WebP lossless
  • Animated images: WebP > GIF for both size and quality
  • Print: TIFF or PNG (lossless, high bit depth)
  • Simple monochrome shapes: SVG (vector, resolution-independent)

Quality settings and perception

JPEG quality 75–85 is virtually indistinguishable from the original in side-by-side viewing for most photographs. Below 60, artifacts become visible: blocking on smooth gradients, mosquito noise around edges, color bleeding.

Save-with-quality-N is a starting point, not a finishing one. Perceptual tools like Butteraugli (Google) and SSIMULACRA2 measure visual difference in a way that correlates with human judgment and can automatically find the highest quality setting that keeps a difference imperceptible.

Responsive images and delivery

Serving a single image at full resolution to all devices wastes bandwidth on smaller screens. The HTML srcset and <picture> elements let you provide multiple resolutions, and the browser picks the best for the viewport.

Modern CDNs can perform format negotiation automatically — serving AVIF to capable browsers, WebP to older ones, and JPEG as a fallback. Combined with responsive sizing, this typically reduces image bytes shipped by 40–70% without any perceivable quality difference.

About the author
RC
Renato Candido dos Passos
Fundador e especialista em Blockchain, Fonoaudiologia e Finanças

Founder of UtilizAí, with a background in Blockchain, Cryptocurrencies and Finance in the Digital Era, plus complementary studies in Theology, Philosophy and ongoing coursework in Speech-Language Pathology. Learn more.

Frequently asked questions

Why does my PNG file get bigger when I re-save it as JPEG?

Usually because the source is a screenshot or diagram with sharp edges and flat color regions — the opposite of what JPEG is optimized for. JPEG always produces non-trivial files even at high quality. PNG is the right choice for such content.

Should I switch everything to AVIF?

Eventually yes, but provide WebP and JPEG fallbacks during the transition. Browser support for AVIF is strong on modern browsers but older versions still need JPEG. Use a <picture> element with multiple sources for graceful degradation.

Does resizing before compressing help?

Enormously. Downscaling a 4000×3000 image to the 1200px width it will actually be displayed at typically produces files 5–10× smaller than compressing the original aggressively. Always resize to the intended display size first, then apply quality compression.

Is it worth running multiple optimization passes?

Modern tools like MozJPEG, libjpeg-turbo, and Squoosh apply optimal encoding in a single pass. Running multiple compression passes on a lossy file (JPEG→JPEG) only makes quality worse — each pass quantizes again. Work from the lossless original whenever possible.

Are there tools to automate this?

Yes. Command-line tools (cwebp, avifenc, pngquant, mozjpeg, oxipng) can be scripted into build pipelines. Web services like Squoosh provide an interactive visual comparison. Cloud-based image CDNs (Cloudflare Images, imgix, Cloudinary) handle format negotiation and quality selection automatically.

Related guides