Micro Tool Yard logo
Tools

Guide

Lossless vs. Lossy Image Compression

The real difference between formats like PNG and JPEG, when each one is the right choice, and how to pick quality settings that actually make sense.

Every image file format makes a trade-off between file size and fidelity, and understanding that trade-off is the difference between an image that compresses cleanly and one that comes out looking noticeably worse than it needed to. The core distinction almost everything else builds on is lossless versus lossy compression.

Lossless: every pixel comes back exactly

A lossless format compresses data in a way that can be perfectly reversed — decompress it and you get back the exact same pixel values you started with, bit for bit. PNG is the most common example: it uses a variant of the DEFLATE algorithm (the same family used by ZIP files) to find repeating patterns in the image data and represent them more compactly, without throwing anything away. This is why PNG is the standard choice for screenshots, logos, icons, and anything with sharp edges, flat color regions, or text — content with a lot of exact repetition compresses extremely well losslessly, and any loss of fidelity in this kind of image (especially around text edges) is immediately, distractingly visible.

Lossy: throwing away what you probably won't notice

A lossy format instead makes a deliberate bet: it discards information that human vision is statistically less sensitive to, in exchange for a much smaller file. JPEG is the classic example. It works by converting the image into a frequency representation (via a discrete cosine transform) and then compressing more aggressively in the high-frequency components — roughly, the fine detail and sharp transitions — while preserving the low-frequency components — the broad shapes, colors, and gradients — more faithfully. This works well because it mirrors something real about human vision: we're much better at noticing errors in smooth gradients and broad shapes than in fine, busy detail.

This is exactly why JPEG is a poor fit for the same kind of content PNG excels at. Compress a screenshot with sharp black text on a white background as a JPEG, and you'll see faint colored haloing ("ringing artifacts") around every letter — the algorithm's frequency-domain assumptions break down around hard, high-contrast edges. But compress a photograph — where detail is naturally soft and gradual, and where the eye is looking at the whole scene rather than any one hard edge — and JPEG can shrink the file to a fraction of its lossless size with changes that are genuinely difficult to spot.

Quality settings: what the number actually controls

JPEG's "quality" slider (typically 0–100) doesn't map to a single simple concept, but broadly it controls how coarsely the frequency components are quantized — lower quality means more aggressive rounding of those frequency values, which both shrinks the file and discards more detail. The relationship between quality and file size isn't linear: dropping from 100 to 90 often cuts file size dramatically with almost no visible difference, because quality 100 stores far more precision than the eye can use. Dropping from 40 to 30, on the other hand, tends to produce a much smaller further size reduction for a much more visible quality hit, because you're already deep into visibly-lossy territory. In practice, quality settings in the 75–85 range are a reasonable default for most photographic content — high enough that artifacts are hard to spot at normal viewing sizes, low enough to get a meaningfully smaller file than the source.

Where WebP and other modern formats fit

Newer formats like WebP support both lossy and lossless modes in a single container, using more modern compression techniques than JPEG or PNG's older algorithms. In lossy mode, WebP typically achieves noticeably smaller files than JPEG at a comparable visual quality, because it can use more sophisticated prediction across blocks of the image. In lossless mode, it generally beats PNG for the same reason. The trade-off is compatibility: while support is now close to universal in modern browsers, some older software and workflows still expect JPEG or PNG specifically, so format choice sometimes comes down to where the image needs to work, not just how small it can get.

A simple decision rule

You can skip most of the theory above with one practical question: does this image have hard edges, text, or flat color regions that need to stay crisp? If yes — a screenshot, a logo, a diagram, a scanned document page with text — use a lossless format (PNG, or lossless WebP if file size matters more). If no — a photograph, a complex natural scene, a background image where smooth gradual detail dominates — a lossy format at a moderate-to-high quality setting (JPEG, or lossy WebP) will usually give you a much smaller file with a difference in quality that's genuinely hard to notice at normal viewing distance.

And when in doubt for anything that matters (an image you might want to re-edit or re-compress later), keep a lossless master copy around. Lossy compression is one-way: you can always compress a lossless image down to a smaller lossy version later, but you can never recover the detail a lossy compression pass has already thrown away.