Media Optimization • 10 min read

Lossless vs. Lossy Image Compression: Algorithms, Formats (WebP, AVIF, JPEG), and Web Performance

Understand the mathematical foundations of image compression. Compare how lossless algorithms preserve pixel fidelity while lossy techniques exploit human visual perception to shrink file sizes by up to 90% without discernible quality loss.

By HundredForge Engineering Team — Media Processing (Computer Graphics & Visual Perception) • Published July 2026

Key Takeaways

  • Lossless compression (PNG, WebP Lossless) removes redundant bit patterns without altering a single pixel value.
  • Lossy compression (JPEG, WebP Lossy, AVIF) leverages Human Visual System (HVS) psychology to discard subtle high-frequency color variations that the human eye cannot perceive.
  • Chroma subsampling (4:2:0) halves color resolution while preserving luminance (brightness), achieving an immediate 50% data reduction before compression even begins.
  • Modern next-gen formats like WebP and AVIF deliver 30% to 50% better compression efficiency than legacy JPEG at equivalent visual fidelity.

1. The Human Visual System & Perceptual Compression

Why can an image file be compressed from 8 Megabytes down to 450 Kilobytes without looking obviously degraded? The secret lies in the biology of human vision.

The human eye has roughly 120 million rod cells (which detect light intensity, luminance, and edges) but only 6 to 7 million cone cells (which perceive color). As a result, humans are exceptionally sensitive to subtle changes in brightness, but relatively insensitive to minute variations in color hue and saturation.

Lossy compression exploits this evolutionary trait. By converting RGB color data into the YCbCr color space (Y = Luminance, Cb = Blue-difference chroma, Cr = Red-difference chroma), compression algorithms can aggressively compress or subsample the chroma channels while preserving sharp luminance detail.

2. The Discrete Cosine Transform (DCT) & Quantization

The engine of classical JPEG compression is the Discrete Cosine Transform (DCT). An image is broken into 8x8 pixel blocks. The DCT transforms each 8x8 block from the spatial domain (pixel values) into the frequency domain (a matrix of cosine wave amplitudes).

The top-left corner of the frequency matrix represents low-frequency information (general shapes, smooth gradients), while the bottom-right corner represents high-frequency detail (fine textures, sharp noise).

The actual "loss" occurs during Quantization: high-frequency coefficients are divided by a quantization matrix and rounded to the nearest integer. Most high-frequency values become zeros. Finally, Huffman encoding or arithmetic coding compresses the repeating zeros into an ultra-compact bitstream.

[Spatial Domain: 8x8 Pixels]
          ↓ Discrete Cosine Transform (DCT)
[Frequency Domain: Amplitudes Matrix]
          ↓ Quantization (Quality Factor Setting)
[Quantized Matrix: High-Frequency Zeros]
          ↓ Zig-Zag Scan + Run-Length / Huffman Encoding
[Compressed Binary ByteStream]

3. Modern Formats: JPEG vs. PNG vs. WebP vs. AVIF

Choosing the right format is the foundation of high-performance web engineering. Modern web browsers now support modern image formats natively across desktop and mobile devices.

FormatCompression TypeTransparency (Alpha)Ideal Use CaseEfficiency vs JPEG
JPEGLossy onlyNoLegacy fallback for photographsBaseline (1.0x)
PNGLossless onlyYesLogos, screenshots, pixel artHeavy for photos
WebPBoth Lossy & LosslessYesGeneral web replacement for JPEG/PNG25% - 35% smaller
AVIFBoth (AV1-based)YesHigh-fidelity photography, modern web40% - 50% smaller

4. Impact on Core Web Vitals (LCP & CLS)

Google Search rankings directly reward websites that pass Core Web Vitals. Uncompressed hero images are the single most common cause of failing the Largest Contentful Paint (LCP) metric.

By compressing images to under 150KB and converting them to WebP or responsive AVIF formats with proper width and height attributes (to prevent Cumulative Layout Shift), web pages load in under a second even on mobile 4G networks.