How Image Compression Works
Understand dimensions, quality, lossy and lossless encoding, and how to make an image smaller without guessing at one quality slider.
Updated September 5, 2026
On this page
Compression solves more than one problem
An image file contains pixels plus instructions and metadata. Making it smaller can mean reducing pixel dimensions, encoding the same pixels more efficiently, discarding detail that is difficult to notice, or removing information that is not required for display.
The best result usually combines several small decisions instead of pushing one quality control to its minimum.
Start with pixel dimensions
A 4000 by 3000 photograph contains twelve million pixels. If the page displays it at 1000 by 750, the browser still has to transfer and decode the oversized file unless you create a smaller variant. Resizing removes work before compression begins and often produces the largest predictable saving.
Keep enough pixels for the largest intended display and high-density screens, but do not publish the full camera original by default. Set width and height attributes in HTML to prevent layout movement.
Lossless and lossy encoding
Lossless compression stores pixels in a more efficient form without changing the decoded result. It is appropriate for pixel art, screenshots, diagrams and intermediate assets that may be edited again.
Lossy compression removes selected visual information. It is usually the practical choice for web photographs because a small amount of controlled loss can reduce file size substantially. The quality number is specific to the encoder; quality 80 in one format is not guaranteed to match quality 80 in another.
What a quality slider changes
At lower quality, an encoder represents blocks, colors and fine detail with less information. Problems first appear around text, high-contrast edges, hair, foliage, gradients and dark noise. Chroma subsampling may reduce color detail more aggressively than brightness detail because human vision is often less sensitive to fine color variation.
Do not inspect only the center of a clean photograph. Include difficult crops in your test set: red text, transparent edges, skin, sky gradients and shadows.
Format and metadata
JPEG is widely interoperable for photographs. WebP and AVIF can provide efficient modern delivery. PNG is valuable when transparency or exact pixels matter, but it is rarely the smallest option for a photograph. SVG describes vector paths and is better than any raster format for many icons and diagrams.
Camera files may also contain EXIF fields, embedded previews, color profiles and other metadata. Some metadata is necessary for correct color or orientation; other fields, such as location, may be private and add bytes without helping the viewer.
A repeatable compression workflow
- Preserve the original in a private source archive.
- Correct orientation and crop the composition.
- Resize to the largest required display size.
- Choose a format suited to the content.
- Export at a moderate quality setting.
- Compare against the source at actual display size.
- Lower quality gradually until the next reduction is no longer worth the visible damage.
- Verify metadata, transparency and color after export.
For responsive websites, create several widths and let srcset select an appropriate candidate. Sending a small image to a narrow viewport is often more valuable than finding a few extra percent in a single large file.
Common mistakes
- Re-encoding a lossy file repeatedly, which compounds artifacts.
- Comparing formats at different dimensions.
- Removing a color profile without checking the resulting colors.
- Using PNG for every photograph because it sounds higher quality.
- Judging only file size and ignoring decode time or visual stability.
- Compressing first and resizing afterward.
A useful stopping rule
Choose the smallest file that still looks correct in its real context. A technically smaller image is not an improvement if product text becomes fuzzy, a face looks waxy or a transparent logo gains a fringe. Measure the page after the change and keep a reproducible export recipe.