MY WEBCAM TEST GUIDE

Lossy Image Compression Techniques and Algorithms Explained

How lossy image compression works: color conversion, chroma subsampling, transforms, prediction, quantization and entropy coding, plus how common formats differ.

What lossy image compression does

Lossy image compression makes files smaller by permanently discarding information that viewers are less likely to notice. Instead of storing every pixel exactly, the encoder converts the image into a representation where fine detail and subtle color differences can be approximated, then stores those approximations compactly. The decoded image looks similar to the original but is not identical, and the discarded data cannot be restored.

Most lossy algorithms combine a small set of techniques, applied in roughly this order:

  • Color space conversion, separating brightness from color
  • Chroma subsampling, storing color at lower resolution than brightness
  • Prediction, guessing a block from pixels already encoded
  • Transform coding, turning pixel blocks into frequency components
  • Quantization, rounding those components so many become zero
  • Entropy coding, packing the result into as few bits as possible

Only some of these steps actually lose information. Quantization is the main lossy step, and chroma subsampling also discards data. Color conversion, transforms and entropy coding are designed to be reversible or nearly so. The quality setting in an editor or export dialog mostly controls how aggressive quantization is, which is why the same setting can produce very different file sizes for different images.

How the main algorithms work

Color conversion and chroma subsampling

Human vision is more sensitive to changes in brightness than to changes in color. Encoders exploit this by converting RGB pixels into a luma channel (brightness) and two chroma channels (color difference), commonly called YCbCr. The chroma channels can then be stored at reduced resolution. In the widely used 4:2:0 scheme, color is kept at half the width and half the height of the brightness channel. This works well for photos but can blur sharp colored edges, such as red text on a blue background.

Transform coding

A transform rewrites a block of pixels as a sum of patterns ranging from smooth to finely detailed. Baseline JPEG uses the discrete cosine transform (DCT) on 8x8 pixel blocks. JPEG 2000 uses a wavelet transform over the whole image, which avoids hard block boundaries. Newer codecs such as those behind WebP, AVIF and HEIC use DCT-like transforms with a choice of block sizes, so flat areas can use large blocks and detailed areas small ones. The transform itself does not shrink the data; it concentrates most of the visual information into a few values, which makes the next step effective.

Prediction

Many modern codecs predict each block from neighboring pixels that have already been encoded, for example by extending edges or gradients into the new block. Only the difference between the prediction and the real pixels, called the residual, is transformed and stored. Good prediction leaves small residuals, which compress well. This intra-frame approach comes from video coding, which is why several still-image formats are based on video codecs.

Quantization

Quantization divides each transform value by a step size and rounds the result. Fine-detail components are usually given larger steps, so many of them round to zero. Larger steps mean smaller files and more visible loss. Encoders can vary the step size across the image, spending more bits on areas where errors would be noticeable, such as faces or smooth gradients, and fewer on busy textures that hide errors.

Entropy coding

The final stage is lossless. Techniques such as Huffman coding and arithmetic coding assign short codes to common values and long codes to rare ones. Because quantization produces long runs of zeros and a few small numbers, this stage can shrink the data considerably without changing it.

Color quantization and other approaches

Not every lossy method uses transforms. Color quantization reduces an image to a limited palette, often with dithering to simulate missing shades. GIF is limited to a palette of at most 256 colors, and palette reduction is also used to shrink PNG files, which makes an otherwise lossless format lossy in practice. Vector quantization and fractal compression were researched as alternatives but are rarely used in mainstream image formats today.

Common lossy formats at a glance

  • JPEG: DCT on 8x8 blocks, chroma subsampling, Huffman or arithmetic coding; no transparency channel
  • JPEG 2000: wavelet transform, supports both lossy and lossless modes
  • WebP (lossy): block prediction and DCT-like transform derived from the VP8 video codec; lossy WebP can carry an alpha channel for transparency
  • AVIF: based on the AV1 video codec, with flexible block sizes and several transform types
  • HEIC/HEIF: container commonly used with HEVC-coded images, frequent on phones and some cameras
  • JPEG XL: supports a DCT-based lossy mode with variable block sizes and can losslessly repack existing JPEG files

Support for these formats, and for features such as transparency, high bit depth or animation, depends on the specific browser, operating system, editor and version. Check the software you and your recipients actually use before choosing a file format.

Applying the techniques to your own images

Knowing which step does what helps you pick settings for webcam snapshots, screenshots, profile pictures or frames captured from video calls:

  • Photos and camera frames: transform-based lossy formats handle natural textures and noise well; start at a medium-high quality setting and lower it while checking the result at actual size
  • Screenshots, text and interface captures: sharp edges and flat colors expose chroma subsampling and quantization artifacts, so a lossless format or a lossy encoder set to high quality without chroma subsampling is usually the safer choice
  • Images that need transparency: avoid JPEG; use a format that stores an alpha channel and confirm the target application displays it correctly
  • Images you will edit again: keep a lossless master and export lossy copies only for sharing
  • Webcam and low-light images: sensor noise is detail the encoder tries to preserve, so noisy images often compress less efficiently than clean ones at the same quality setting

Resizing usually matters more than any quality slider. Reducing pixel dimensions to the size the image will actually be displayed at removes data before compression even starts. Keep the aspect ratio locked when resizing so the image is not stretched, and crop rather than distort if the destination needs a different shape.

Limits and related questions

Can discarded detail be recovered?

No. Converting a lossy file to a lossless format preserves the image as it is now but does not bring back what quantization removed. Upscaling or AI enhancement tools can generate plausible detail, but that detail is synthesized, not restored.

Why do compression artifacts look the way they do?

Each artifact traces back to a specific step. Blocky squares come from coarse quantization of independent blocks. Ringing or halos near edges appear when fine-detail components are rounded away. Banding in skies and gradients results from too few distinct values surviving quantization. Color bleeding around sharp edges is a sign of chroma subsampling.

Does saving a lossy file again reduce quality?

Usually yes. Each decode and re-encode cycle can introduce new rounding errors, a problem known as generation loss. It is most noticeable when the image is also resized, cropped off the block grid or edited between saves. Some tools can perform specific operations, such as certain rotations, without full re-encoding, but this depends on the tool and should be verified rather than assumed.

Does compression remove metadata or protect privacy?

Compression algorithms act on pixel data; metadata such as camera details, timestamps or location tags is handled separately by the software that writes the file. Some exporters keep it, some strip it, and behavior can change between versions. If metadata matters, inspect the output file. When using an online compressor, check the service's own documentation on whether images are uploaded, stored or processed locally in the browser rather than assuming either.