How Image Compression Works — JPEG, PNG & WebP Explained

Image files on the web need to be small enough to load quickly and clear enough to look good. Three formats handle this trade-off in different ways: JPEG uses lossy compression designed for photographs, PNG uses lossless compression for graphics with sharp edges, and WebP is a modern format that handles both efficiently.

Lossy vs Lossless Compression

Lossless compression reduces file size without removing any data — the original can be perfectly reconstructed from the compressed file. PNG uses lossless compression.

Lossy compression achieves smaller file sizes by permanently discarding data the algorithm determines is least perceptible to the human eye. JPEG and WebP (in lossy mode) use lossy compression. Once compressed, the discarded data cannot be recovered.

JPEG — Best for Photographs

JPEG (Joint Photographic Experts Group) was designed for photographs with continuous tonal variations. It works by applying the Discrete Cosine Transform (DCT) to blocks of 8×8 pixels, then discarding high-frequency detail.

At high quality settings (85–95), JPEG files look nearly identical to the original. At lower settings (50–75), compression artifacts — blocky patterns around edges — become visible.

JPEG does not support transparency. Use PNG or WebP when you need a transparent background.

PNG — Best for Graphics & UI

PNG (Portable Network Graphics) uses DEFLATE lossless compression. Because nothing is discarded, PNG preserves every pixel exactly. This makes it ideal for logos, icons, screenshots, and any image with sharp edges or text.

PNG supports full alpha transparency. However, PNG files are significantly larger than JPEG for photographic content.

WebP — The Modern Choice

WebP was developed by Google and supports both lossy and lossless compression. Lossy WebP typically produces files 25–35% smaller than equivalent JPEG at similar quality. Lossless WebP is typically 26% smaller than PNG.

WebP also supports transparency (like PNG) and animation (like GIF). It is supported by all modern browsers. For new web projects, WebP is generally the best choice for most images.

Choosing a Quality Level

For JPEG and lossy WebP, quality is a dial between file size and visual fidelity. A quality setting of 75–85 is a good starting point for most web images — visually excellent and meaningfully smaller than the original. For hero images where quality is critical, 85–92 is reasonable. For thumbnails and secondary images, 60–75 saves significant bandwidth.

Example

File size comparison for a product photo

A 3000×2000 product photograph: Original TIFF = 17 MB. JPEG at 85% = 1.2 MB. WebP at 75% = 800 KB. The WebP version loads in under 200ms on a typical mobile connection; the TIFF would take over 30 seconds.

Practical notes

  • •Never re-save a JPEG from another JPEG — each save applies compression again and degrades quality. Always work from the original high-quality source.
  • •SVG is not covered here — it is a vector format (mathematical descriptions of shapes), not a raster pixel format.

Try the tools

Frequently asked questions

When should I use PNG instead of JPEG?

Use PNG for logos, icons, screenshots, and any image with text or sharp geometric edges. Use JPEG for photographs and images with complex color gradients.

Is WebP safe to use for all users?

WebP is supported by Chrome, Edge, Firefox, and Safari (since Safari 14). If you need to support very old browsers, provide a JPEG fallback using the HTML <picture> element.

Does compressing an image make it load faster?

Yes — smaller file size means less data to transfer. A 200 KB image loads roughly 5× faster than a 1 MB image on a slow mobile connection.