What Is Image Compression? Lossy vs Lossless Explained
Image compression reduces file size by encoding pixel data more efficiently. Lossy compression discards some data for smaller files; lossless compression preserves everything. Here's how each works.
Advertisement
A raw uncompressed photograph from a modern smartphone might be 20–30 MB. The JPEG you save from your camera is typically 3–8 MB. The WebP you serve on your website might be 80–200 KB. That 99% reduction in size is achieved by image compression — encoding the visual data more efficiently, and in some cases discarding visual detail that humans can't easily perceive.
What Is Image Compression?
Image compression is the process of reducing an image's file size by encoding its pixel data using mathematical algorithms. The goal is to represent the same (or near-identical) visual information in fewer bytes, making images faster to transmit and cheaper to store.
All digital images are ultimately grids of pixels, each pixel a combination of red, green, and blue (and sometimes alpha/opacity) values. Raw, uncompressed images store every pixel's full value. Compression algorithms exploit patterns in the data — repeated colours, predictable gradients, redundant information — to store the same visual content in fewer bits.
Lossy vs Lossless Compression
Lossy vs lossless image compression compared
| Property | Lossy | Lossless |
|---|---|---|
| Quality after compression | Some data discarded, quality reduced | Perfect — identical to original |
| File size reduction | Large (60–95% smaller than raw) | Moderate (20–60% smaller than raw) |
| Best for | Photographs, hero images | Screenshots, logos, graphics with text |
| Re-saving penalty | Additional quality loss each save | No penalty, saves are identical |
| Formats | JPEG, lossy WebP, lossy AVIF | PNG, lossless WebP, lossless AVIF |
| Reversible? | No — discarded data is gone | Yes — original can be reconstructed |
Advertisement
How Lossy Compression Works
Lossy compression works by identifying visual information that human eyes are least sensitive to and discarding it. JPEG, for example, uses the Discrete Cosine Transform (DCT): the image is divided into 8×8 pixel blocks, then each block is transformed into frequency components. High-frequency details (fine texture, sharp edges) are quantised more aggressively — rounded to fewer possible values — because human vision is less sensitive to high-frequency information than to low-frequency (broad colour areas, gradients).
WebP and AVIF use more sophisticated lossy algorithms from video codecs. Instead of fixed 8×8 blocks, they use variable block sizes (from 4×4 to 64×64 or larger) and more complex prediction of each block from surrounding pixels. This allows them to achieve better quality at the same file size, or the same quality at a smaller file size, compared to JPEG.
Re-saving lossy images
Every time you re-save a lossy image (edit a JPEG and save as JPEG), you lose more quality. The degradation compounds. For images you'll edit, always work from a lossless source (RAW, PNG, or lossless WebP) and export lossy only for the final deliverable.
How Lossless Compression Works
Lossless compression keeps every pixel's exact value but encodes runs of similar pixels more efficiently. PNG uses the DEFLATE algorithm (the same algorithm as ZIP files) applied to prediction-filtered pixel data. First, a filter transforms each pixel into a prediction error (how far the actual pixel differs from what adjacent pixels predict it would be). These prediction errors tend to be small and clustered near zero — which DEFLATE compresses very efficiently.
WebP lossless uses a more advanced transform-based approach, applying colour indexing, colour space transformation, and 2D LZ77 back-reference encoding. The result: lossless WebP is typically 26% smaller than equivalent PNG, representing the same pixels but encoded more cleverly.
Compress Images Free in Your Browser
Our image compressor handles JPEG, PNG, and WebP. Adjust quality to find the right balance.
Which Formats Use Which Compression
Image format compression types
| Format | Lossy | Lossless | Both |
|---|---|---|---|
| JPEG (JPG) | Yes | No | — |
| PNG | No | Yes | — |
| GIF | No* | Yes | — (*only 256 colours) |
| WebP | Yes | Yes | Both |
| AVIF | Yes | Yes | Both |
| SVG | N/A (vector) | N/A | — |
| HEIC | Yes | Yes | Both |
Advertisement
Quality Settings Explained
Most image tools expose a quality slider for lossy compression, typically 0–100. Higher quality = larger file, lower quality = smaller file. The relationship isn't linear — quality 90 is often 3–5× larger than quality 70, while looking only marginally better to the eye.
- Quality 95–100: Near-lossless, huge files. Useful for post-production; avoid for web.
- Quality 85–90: High quality, still larger than needed for web. Used in professional print-adjacent workflows.
- Quality 75–85: The web sweet spot for photographs. Imperceptible quality loss, significantly smaller files.
- Quality 60–75: Noticeable quality loss on close inspection. Acceptable for thumbnails and small previews.
- Quality below 60: Visible artefacts. Only acceptable for very small images or aggressive size constraints.
How to Choose Compression Level
The best compression setting is the highest compression (lowest quality number) at which quality loss becomes invisible at normal viewing distance on a normal screen. For web images, WebP quality 80–85 achieves this for most photographs. For product images where customers zoom in, use 85–90. For thumbnails and previews, 70–75 is typically fine.
Visual comparison tip
Use a side-by-side comparison tool (like Squoosh or AllConverter's image compressor) to view your original and compressed image simultaneously. Zoom to 100% and look for artefacts around sharp edges, text, and fine details.
Try Our Image Compressor
Compress images with quality control. Preview before downloading. Runs entirely in your browser.
Advertisement
Frequently Asked Questions
What is image compression?
Image compression is the process of reducing an image file's size by encoding its pixel data more efficiently. Lossless compression preserves every pixel perfectly; lossy compression discards visual information human eyes are less sensitive to, achieving much smaller files.
Does compressing an image reduce quality?
Lossy compression does reduce quality, but at appropriate settings (WebP quality 80–85, JPEG quality 85–90) the quality loss is invisible to human eyes on a screen. Lossless compression (PNG, lossless WebP) never reduces quality.
What is the difference between lossy and lossless compression?
Lossy compression permanently discards some visual data to achieve much smaller files — like JPEG and WebP (lossy). Lossless compression preserves every pixel exactly but still achieves smaller files through smarter encoding — like PNG and WebP (lossless). Lossy files are typically 60–80% smaller than lossless at similar visual quality.
Which image format has the best lossless compression?
WebP lossless is currently the best widely-supported lossless format, achieving about 26% smaller files than PNG for the same image. AVIF lossless also performs well but has less software support.
Can I restore a compressed JPEG to its original quality?
No. Lossy compression permanently discards data — once the detail is gone, it cannot be recovered. Always keep your original source file in a lossless format (RAW, TIFF, or PNG) and export lossy versions as needed.
What quality setting should I use for web images?
For WebP: quality 80–85 for photographs, lossless for graphics and screenshots. For JPEG (if you must): quality 85–90. These settings deliver imperceptible quality loss on web-viewed images at significantly smaller file sizes.