Skip to content
← Back to Blog

The Ultimate Image Compression Guide for Web

Images account for ~50% of total page weight on most websites. For image-heavy sites like e-commerce and portfolios, that number can reach 70-80%. Properly compressing your images is the single biggest win for page speed, Core Web Vitals, and SEO — often more impactful than any code optimization.

Why Image Compression Matters

The numbers make a compelling case:

  • 53% of mobile users abandon pages that take over 3 seconds to load (Google data)
  • Every 100ms of delay costs e-commerce sites 1% in conversions (Akamai research)
  • Google's Core Web Vitals directly measure LCP (Largest Contentful Paint), which is almost always an image
  • Smaller images mean lower hosting costs — bandwidth is expensive at scale

Understanding Compression Types

Lossy Compression

Lossy compression permanently removes image data that the algorithm determines is least visible to the human eye. The key techniques include:

  • Chroma subsampling — reduces color resolution (human eyes are more sensitive to brightness than color)
  • Frequency quantization — removes high-frequency details that are less perceptible
  • Predictive coding — encodes differences from predicted values rather than absolute values

Used by: JPEG, WebP (lossy mode), AVIF

Best for: Photographs, complex images, hero banners — any image where minor detail loss is acceptable for dramatic file size reduction.

Lossless Compression

Lossless compression reduces file size without any data loss. The decompressed image is bit-for-bit identical to the original. Techniques include:

  • DEFLATE — used by PNG, combines LZ77 and Huffman coding
  • Prediction filters — PNG applies row-by-row predictions to exploit pixel correlations
  • Dictionary coding — identifies and references repeated byte patterns

Used by: PNG, WebP (lossless mode), GIF

Best for: Screenshots, logos, technical diagrams, text-heavy images — anything where every pixel matters.

Visual Comparison

AspectLossyLossless
File size reduction70-95%10-50%
Quality preservationNear-perfect (at high settings)Perfect
Re-save degradationYes (generational loss)No
Best for photos✅ Excellent❌ Huge files
Best for graphics❌ Artifacts on sharp edges✅ Perfect edges

Format-by-Format Compression Guide

JPEG Compression

JPEG uses DCT-based lossy compression with a quality slider from 1-100. Understanding what happens at different quality levels:

QualityFile SizeVisual QualityRecommended For
95-100LargeIndistinguishable from originalArchival, print
85-90MediumExcellent — differences require zoomingHigh-quality web
75-85SmallVery good — minor softeningGeneral web, blog images
60-75Very smallGood — some artifacts visible on zoomThumbnails
Below 60TinyPoor — visible blocking artifactsNot recommended

Pro tip: JPEG quality 80-85 is the sweet spot. Below 75, blocking artifacts become visible in smooth gradients. Above 90, file sizes increase significantly with minimal visual improvement.

WebP Compression

WebP uses VP8-based lossy compression that's 25-35% more efficient than JPEG. Key differences:

  • WebP quality 80 ≈ JPEG quality 85 in perceptual quality
  • WebP handles gradients and smooth areas better than JPEG (fewer blocking artifacts)
  • WebP lossless mode is 26% smaller than PNG on average

AVIF Compression

AVIF achieves the best compression ratios available:

  • AVIF quality 60 ≈ JPEG quality 85 ≈ WebP quality 80 in perceptual quality
  • 50% smaller than JPEG, 20% smaller than WebP at equivalent quality
  • Encoding is 5-10× slower — plan for build-time optimization, not real-time

PNG Optimization

While PNG is lossless, you can still optimize it significantly:

  • Color quantization — reduce from 24-bit to 8-bit (256 colors) where possible. Tools like pngquant achieve 60-80% reduction with minimal visual change
  • Remove unnecessary chunks — strip metadata, text chunks, ICC profiles
  • Optimize DEFLATE — tools like oxipng try multiple compression strategies to find the smallest result

Best Practices for Core Web Vitals

  1. Serve correctly sized images — don't serve a 4000px image for a 400px container. Use srcset for responsive images
  2. Use modern formats with fallbacks — AVIF → WebP → JPEG via the <picture> element
  3. Lazy load below-the-fold images — add loading="lazy" to images not visible on initial page load
  4. Set explicit width and height — prevents Cumulative Layout Shift (CLS). The browser can reserve space before the image loads
  5. Use a CDN — serve images from edge locations near your users for lower TTFB
  6. Preload critical images — use <link rel="preload"> for your LCP image to prioritize its loading
  7. Use decoding="async" — allows the browser to decode images off the main thread
  8. Implement responsive images — use srcset and sizes to serve appropriately sized images for each viewport

Responsive Images: The Complete Pattern

<picture>
  <!-- AVIF for modern browsers -->
  <source
    type="image/avif"
    srcset="img-400.avif 400w, img-800.avif 800w, img-1600.avif 1600w"
    sizes="(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px" />
  <!-- WebP fallback -->
  <source
    type="image/webp"
    srcset="img-400.webp 400w, img-800.webp 800w, img-1600.webp 1600w"
    sizes="(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px" />
  <!-- JPEG final fallback -->
  <img
    src="img-800.jpg"
    srcset="img-400.jpg 400w, img-800.jpg 800w, img-1600.jpg 1600w"
    sizes="(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px"
    alt="Descriptive alt text"
    width="1600" height="900"
    loading="lazy" decoding="async" />
</picture>

Measuring Your Results

After optimizing, verify your improvements with these tools:

  • Google PageSpeed Insights — measures Core Web Vitals and flags image optimization opportunities
  • Lighthouse — built into Chrome DevTools, provides detailed image audit
  • WebPageTest — waterfall view shows exactly how images affect load timing
  • Chrome DevTools Network tab — filter by "Img" to see every image's size and load time

Try It Now

Use our free image converter to compress and convert your images. Set a file size target (e.g., under 500KB) and our tool will automatically adjust quality to fit. Batch processing lets you optimize your entire site in minutes.

Image Optimization Tips

Get weekly tips on image formats, compression, and web performance.

No spam, unsubscribe anytime. We respect your privacy.