Skip to content
Back to Blog

Image Compression Explained: Lossy vs Lossless and When to Use Each

February 28, 2026
15 min read

Understand the difference between lossy and lossless image compression, how each works under the hood, and how to choose the right approach for web, print, and archival use cases.

Joseph Hamawi

Joseph Hamawi

Founder, Kode Foundry · February 28, 2026

Builds browser-based image and PDF tools at Pixly, the consumer brand of Kode Foundry LTD. Privacy-first by default — files are processed in your browser, not on a server.

Why Image Compression Matters

Images account for roughly 50% of the total weight of an average web page. A single uncompressed 24-megapixel photo can be over 70 MB in raw format. Without compression, the modern web would be unusable, pages would take minutes to load, mobile data plans would evaporate, and servers would buckle under the bandwidth demands.

Compression makes images practical by reducing file size while preserving enough visual information for the intended use. The key question is always: how much can we compress before quality loss becomes noticeable?

How Digital Images Work

Before understanding compression, you need to understand what you're compressing.

A digital image is a grid of pixels. Each pixel stores color information, typically three values for Red, Green, and Blue (RGB), each ranging from 0 to 255. That's 8 bits per channel, 24 bits per pixel.

A simple calculation:

  • A 4000 × 3000 pixel photo = 12 million pixels
  • At 24 bits per pixel = 288 million bits = 36 MB
  • That's the raw, uncompressed size

This is why your camera produces such large RAW files. Every format you actually use (JPEG, PNG, WebP) applies compression to reduce this size dramatically.

Color Models and Depth

| Color Model | Bits Per Pixel | Use Case | |-------------|---------------|----------| | Grayscale | 8 | Black & white photos | | RGB 8-bit | 24 | Standard photos, web images | | RGBA 8-bit | 32 | Images with transparency | | RGB 16-bit | 48 | Professional photography, HDR | | CMYK 8-bit | 32 | Print production |

Lossless Compression: Every Pixel Preserved

Lossless compression reduces file size without discarding any information. When you decompress a lossless image, you get back the exact original, every pixel identical, bit for bit.

How Lossless Compression Works

Lossless algorithms exploit redundancy in data. Images contain enormous amounts of redundancy:

Run-Length Encoding (RLE): If 200 consecutive pixels are the same shade of blue, instead of storing "blue, blue, blue..." 200 times, store "blue × 200." This is extremely effective for images with large areas of flat color.

Dictionary-Based Compression (LZW, Deflate): These algorithms build a dictionary of recurring patterns. If the sequence "red, green, blue, red, green, blue" appears repeatedly, it gets a short code instead of being written out each time. PNG uses the Deflate algorithm, which combines LZW-style dictionary coding with Huffman coding for optimal results.

Predictive Coding: Instead of storing absolute pixel values, store the difference from the predicted value. If one pixel is RGB(100, 150, 200) and the next is RGB(102, 151, 199), the difference (2, 1, -1) requires far fewer bits to encode than the absolute values.

Lossless Formats

| Format | Compression Ratio | Transparency | Animation | Best For | |--------|-------------------|-------------|-----------|----------| | PNG | 2:1 to 10:1 | Yes (alpha) | No (use APNG) | Screenshots, graphics, logos | | WebP (lossless) | 25-35% smaller than PNG | Yes | Yes | Web graphics with transparency | | AVIF (lossless) | 20-30% smaller than PNG | Yes | Yes | Modern web, cutting edge | | TIFF (LZW) | 2:1 to 5:1 | Yes | No | Professional photography, print | | BMP (RLE) | Minimal | No | No | Legacy Windows applications | | GIF | 3:1 to 5:1 | Binary only | Yes | Simple animations (256 colors max) |

When to Use Lossless

  • Screenshots and UI elements: Text and sharp edges degrade visibly with lossy compression
  • Logos and icons: Brand assets need exact color reproduction
  • Medical imaging: Diagnostic accuracy requires pixel-perfect fidelity
  • Archival: Master copies should always be lossless
  • Images for further editing: Each lossy save degrades quality further (generation loss)
  • Graphics with text: Lossy compression creates visible artifacts around text edges

Lossy Compression: Calculated Sacrifice

Lossy compression achieves dramatically smaller files by permanently discarding information that the algorithm determines is least noticeable to human vision. You cannot recover the original data from a lossy-compressed image.

How Lossy Compression Works

The most common lossy algorithm (used by JPEG) follows this pipeline:

1. Color Space Conversion: Convert from RGB to YCbCr (luminance + two chrominance channels). Human eyes are far more sensitive to brightness changes than color changes, so the chrominance channels can be compressed more aggressively.

2. Chroma Subsampling: Reduce the resolution of color channels. The most common scheme (4:2:0) keeps luminance at full resolution but halves chrominance resolution in both dimensions, a 75% reduction in color data that's barely perceptible.

3. Block Division: Split the image into 8×8 pixel blocks. Each block is processed independently.

4. Discrete Cosine Transform (DCT): Convert each block from spatial domain (pixel values) to frequency domain (patterns of change). This separates the image into low-frequency components (smooth gradients, large areas) and high-frequency components (fine details, sharp edges).

5. Quantization: This is where data is actually lost. High-frequency components (fine details) are rounded aggressively, often to zero. The quality setting controls how aggressive this rounding is, lower quality means more rounding, smaller files, and more visible artifacts.

6. Entropy Coding: The quantized values are further compressed using Huffman coding or arithmetic coding (lossless step).

Understanding Quality Settings

Quality isn't linear. The relationship between quality setting and file size follows a curve:

| Quality | File Size (relative) | Visual Difference from 100% | |---------|---------------------|---------------------------| | 100% | 100% | None (reference) | | 95% | ~50% | Imperceptible | | 90% | ~35% | Imperceptible to most viewers | | 85% | ~25% | Barely perceptible under close inspection | | 80% | ~20% | Slight softening in detailed areas | | 70% | ~15% | Noticeable softening, minor artifacts | | 50% | ~10% | Visible artifacts, especially around edges | | 30% | ~5% | Significant quality loss, obvious blocking |

The sweet spot for web images is 80-90%. You get 65-80% file size reduction with quality loss that's invisible at normal viewing distances.

Lossy Formats

| Format | Typical Compression | Transparency | Animation | Best For | |--------|-------------------|-------------|-----------|----------| | JPEG | 10:1 to 20:1 | No | No | Photographs, complex images | | WebP (lossy) | 25-35% smaller than JPEG | Yes | Yes | Web photos, modern browsers | | AVIF (lossy) | 30-50% smaller than JPEG | Yes | Yes | Best quality-to-size ratio | | JPEG XL | 35-60% smaller than JPEG | Yes | Yes | Future standard (limited support) |

When to Use Lossy

  • Photographs: Natural images compress extremely well with lossy algorithms
  • Web images: Page speed depends on small file sizes
  • Social media: Platforms recompress your images anyway
  • Email attachments: Smaller files send and download faster
  • Thumbnails and previews: Small display sizes hide compression artifacts

JPEG Artifacts: What Goes Wrong

Understanding JPEG artifacts helps you choose the right quality level:

Blocking: At low quality, the 8×8 block boundaries become visible as a grid pattern. Most noticeable in smooth gradients like skies.

Ringing (Gibbs phenomenon): Halos appear around sharp edges, bright/dark outlines around text, buildings against sky, or any high-contrast boundary.

Color bleeding: Chroma subsampling can cause colors to bleed across sharp boundaries, particularly noticeable where bright colors meet.

Mosquito noise: Shimmering artifacts around edges, named because they look like tiny insects buzzing around the image.

Making the Right Choice

Decision Framework

Ask these questions in order:

  1. Does the image contain text, sharp lines, or transparency? → Use lossless (PNG or WebP lossless)
  2. Is this a master/archival copy? → Use lossless (TIFF or PNG)
  3. Is this for the web? → Use lossy (WebP or AVIF at 80-90% quality)
  4. Is this a photograph? → Use lossy (JPEG at 85-90%, or WebP/AVIF for better compression)
  5. Is this a simple graphic with few colors? → Use lossless PNG (it'll be small anyway)

Hybrid Approaches

Modern formats like WebP and AVIF support both lossy and lossless compression in the same format. Some advanced workflows combine both:

  • Lossy for photographic regions with smooth gradients and natural textures
  • Lossless for text and graphic overlays where artifacts would be visible

Practical Optimization Workflow

For web images, follow this workflow:

  1. Start with the highest quality source: RAW or uncompressed TIFF
  2. Resize to the maximum display size: don't serve 4000px images for 800px display slots
  3. Choose your format based on content type and browser support
  4. Compress with the appropriate quality: 85% for JPEG, 80% for WebP, 75% for AVIF
  5. Verify visually: compare side-by-side at actual display size
  6. Generate multiple sizes for responsive images (srcset)

Tools like Pixly make this process simple, upload your image, choose your output format, and the tool handles the compression with optimal settings. Since everything runs in your browser, your images stay private and the process is instant.

Ready to Convert Your Images?

Fast, secure, and completely free. Try our converter now!

Start Converting

Related Articles