PDFDock Logo
PDFDockFile processor
Conversion & Formatting8 min readUpdated Sep 4, 2026

Lossless vs Lossy Image Compression: JPEG, WebP, and PNG Algorithms Compared

Image files comprise the majority of data transferred across the web and embedded inside PDF documents. Understanding the mathematical mechanics of lossless and lossy compression algorithms allows developers, designers, and office professionals to drastically reduce storage footprint without sacrificing optical clarity. This guide compares the internal mechanics of PNG (DEFLATE), JPEG (DCT), and modern WebP codecs.

PDFDock Engineering Team
Media Compression & Image Codec Specialists

Key Technical Takeaways

  • Lossless compression reconstructs pixel data bit-for-bit identically with zero degradation, ideal for text, charts, and transparent icons.
  • Lossy compression discards psycho-visually redundant color information to achieve 80% to 95% file size reductions.
  • PNG relies on 2D delta filtering followed by LZ77 and Huffman coding (DEFLATE).
  • WebP supports both modern lossy predictive coding and lossless compression, consistently outperforming legacy PNG and JPEG by 25% to 35%.

Table of Contents

1. The Fundamental Difference: Lossless vs Lossy

Every digital image is fundamentally a grid of pixels with color channel intensities (e.g. Red, Green, Blue, Alpha). An uncompressed 4K photograph (3840 x 2160 pixels at 24 bits per pixel) requires **24.8 megabytes** of raw memory: ``` 3840 × 2160 pixels × 3 bytes = 24,883,200 bytes (~24.8 MB) ``` Because storing raw bitmap data is wildly impractical for storage and web transmission, compression algorithms are applied: ### Lossless Compression Lossless algorithms identify mathematical statistical redundancy in the byte stream. When decompressed, the reconstructed image is a 100% bit-for-bit clone of the original file. No visual information is lost. However, maximum compression ratios are typically limited to **2:1 to 3:1** for real-world photos. ### Lossy Compression Lossy algorithms exploit human visual biology (psycho-optics). The human retina is far more sensitive to fine variations in brightness (luminance) than subtle shifts in color (chrominance). By separating luminance from color and quantizing high-frequency details, lossy algorithms achieve compression ratios of **10:1 to 30:1** with virtually imperceptible visual degradation.

2. Inside Lossless PNG: Filters and the DEFLATE Engine

The Portable Network Graphics (PNG) format was engineered to replace GIF. It operates in two sequential stages: 1. **Prediction Filtering (Delta Encoding)**: Before compression, PNG applies one of five prediction filters to each scanline (None, Sub, Up, Average, Paeth). Instead of storing the absolute color of a pixel, it stores the difference between the current pixel and its neighbor. This turns complex color values into long strings of zeroes and small integers. 2. **DEFLATE Algorithm**: The filtered data is compressed using a combination of **LZ77** (which replaces duplicate byte strings with backward pointers) and **Huffman coding** (which assigns shorter bit codes to frequently occurring symbols). Because PNG is purely lossless and supports 8-bit alpha transparency, it is the premier format for screenshots, UI diagrams, and digital signatures.

When compressing PNGs with text or flat graphics, using a tool like [Compress Image](/tools/compress-image/) optimizes palette indexing, reducing file size by up to 60% without losing a single pixel of crispness.

3. Inside Lossy JPEG: The Discrete Cosine Transform (DCT)

The Joint Photographic Experts Group (JPEG) algorithm is specifically engineered for continuous-tone photographic imagery. It follows four mathematical steps: 1. **Color Space Conversion**: The RGB bitmap is converted to **YCbCr** (Y = Luminance, Cb = Blue-difference chroma, Cr = Red-difference chroma). 2. **Chroma Subsampling**: The chroma channels are often downsampled at a 4:2:0 ratio, immediately cutting half the raw color data with near-zero perceptual loss. 3. **Discrete Cosine Transform (DCT)**: The image is divided into 8x8 pixel blocks. The DCT converts spatial pixel intensities into frequency components (representing smooth gradients as low frequencies and sharp edges as high frequencies). 4. **Quantization**: High-frequency coefficients are divided by values in a quantization matrix and rounded to integers. This is the only step where data is permanently discarded. The higher the compression level, the coarser the quantization table.

4. WebP: Next-Gen Hybrid Compression

Developed by Google based on the VP8 video codec, WebP provides both lossy and lossless modes, supporting 24-bit RGB, 8-bit alpha transparency, and color profiles: - **Lossy WebP**: Uses macroblock predictive coding (predicting pixel blocks based on neighboring blocks) followed by transform quantization. It generates files **25% to 34% smaller** than JPEG at equivalent visual quality. - **Lossless WebP**: Uses advanced entropy transforms (spatial prediction, color transforms, green-channel subtraction) yielding files **26% smaller** than PNG. Modern browsers and PDF processors fully support WebP. You can easily transcode images between formats using [Convert Format](/tools/convert-image/).

5. Technical Codec Comparison Matrix

Use this reference matrix when selecting image formats for document inclusion:
FormatCompression TypeAlpha TransparencyBest Used ForTypical Compression Ratio
PNGLossless (DEFLATE)Yes (8-bit alpha)Screenshots, vector diagrams, logos, transparent stamps2:1 – 4:1
JPEGLossy (DCT)No (Opaque only)Photographs, scanned full-color paper documents10:1 – 25:1
WebPHybrid (Lossless & Lossy)Yes (In both modes)Modern web media, compressed document inserts15:1 – 35:1
WebP (Lossless)Lossless (Predictive)Yes (Full alpha)High-fidelity graphics replacing heavy PNGs3:1 – 6:1

Frequently Asked Questions

Can I convert a lossy JPEG back into a lossless PNG to recover quality?▼

No. Once visual data is discarded during lossy compression (quantization), it is permanently gone. Converting a JPEG to PNG only freezes the existing compression artifacts inside a larger lossless container.

Why do text screenshots look blurry when saved as JPEG?▼

JPEG's 8x8 DCT block transforms struggle with high-contrast sharp boundaries (like black text on white backgrounds), generating 'ringing' or halo artifacts around letters. Always use PNG or lossless WebP for text screenshots.

What is the best quality slider setting for JPEG compression?▼

A quality setting between 75% and 82% offers the sweet spot: substantial file size savings (typically 70%-80%) without visible blockiness or color banding.

Can PDF documents contain WebP images?▼

While newer PDF specifications support modern image formats, legacy PDF readers prefer JPEG or FlateDecode PNG streams. PDFDock automatically transcodes images to optimal standards when compiling PDFs.

Recommended PDFDock Tools for This Guide

Related Guides & Analyses