Compression

Image compression explained

Lossy, lossless and what the quality slider really does

What happens to your pixels when you compress a PNG, JPG or WebP, why savings vary so much between images, and how to choose a quality setting without guessing.

On this page

Every image compressor makes the same promise – “smaller files, same quality” – and every one of them is hiding a trade-off somewhere. This guide explains what actually happens when you compress an image so you can read the numbers a tool shows you and decide whether the result is good enough for your purpose.

Two very different kinds of compression

Lossless compression finds a shorter way to write down exactly the same pixels. Decompress the file and you get back every value you started with, bit for bit. PNG is a lossless format; so are lossless WebP, GIF (within its 256-colour limit) and TIFF with LZW. Because nothing is thrown away, the savings depend entirely on how much redundancy the image contains: a screenshot with large flat areas compresses dramatically, a photograph full of noise barely compresses at all.

Lossy compression throws information away on purpose, choosing details that human vision is least likely to notice. JPEG and lossy WebP work this way. The “quality” setting controls how aggressive the discarding is. Lossy compression can shrink a photograph to a tenth of its original size with no visible change, something no lossless method can do, but every pass removes a little more and nothing can be recovered afterwards.

The practical consequence: the right compression depends on the content, not on the format you happen to have. A chart exported as JPG will look worse and be larger than the same chart as a palette PNG; a photo stored as PNG will be several times larger than it needs to be.

Three six-by-six pixel grids. The source and the lossless copy are identical. In the lossy copy each three-by-three block has been replaced by a single averaged value, so fine detail is gone.Source36 valuesLosslessSame 36 values, shorter fileLossy4 values stand in for 36
Lossless compression finds a shorter way to write the same 36 pixel values; lossy compression keeps one averaged value per block, so the file is far smaller but the original detail is gone for good.

What the quality slider changes in JPEG and WebP

JPEG splits the image into 8×8 pixel blocks, converts each block into frequency components (how fast the brightness and colour change across the block) and then rounds those components. The quality setting scales the rounding: at quality 90 the rounding is gentle and most components survive; at quality 50 small high-frequency components round to zero and disappear, which is why low-quality JPEGs look blurry and show blocky patterns around sharp edges.

Two further things happen before the frequency step. Colour is converted to a brightness channel plus two colour channels, and the colour channels are usually stored at half resolution (“chroma subsampling”), because our eyes resolve brightness much more finely than colour. Most encoders switch chroma subsampling on at lower quality values, which is one reason red text on a photo can look smeared after compression.

WebP’s lossy mode is built on the VP8 video codec. It also works in blocks and also uses a quality value from 0 to 100, but it predicts each block from its neighbours before encoding the difference, and it applies a deblocking filter afterwards. The result is that WebP typically needs 25–35 % fewer bytes than JPEG for similar visual quality – a figure that holds for most photographs but varies with content, so always compare the real output size rather than assuming the saving.

A useful rule of thumb for both formats:

Quality What you see Typical use
90–100 Visually identical to the source; files grow quickly above 92 Archival copies, print
80–89 Hard to distinguish from the source at normal viewing sizes Product photos, portfolios
70–79 Faint softening in fine detail; still clean for most content Blog and article images
50–69 Visible artefacts around edges and in gradients Thumbnails, previews
Below 50 Obvious blocking and colour banding Rarely acceptable

The numbers are not interchangeable between encoders. Quality 80 in one program does not produce the same file as quality 80 in another, because each encoder uses its own rounding tables. The only reliable comparison is to look at the output.

Why PNG compression works differently

PNG never discards pixel data on its own, so a “PNG compressor” has to take one of two routes.

The lossless route keeps every pixel and simply tries harder to find a compact encoding. PNG encodes each row with one of five filters that predict a pixel from its neighbours, then compresses the filtered bytes with the DEFLATE algorithm (the same algorithm used by ZIP). An optimiser such as OxiPNG tries different filter choices and compression strategies and keeps the smallest result, and it can drop metadata chunks that the image does not need. Savings are real but modest – a few percent to perhaps 20 % on files produced by a careless exporter, and often nothing at all on a file that was already optimised.

The lossy route reduces the number of distinct colours. Standard PNG stores 8 bits per channel, allowing over 16 million colours. If the image can be approximated with a palette of 256 colours or fewer, every pixel needs only one byte instead of three or four, and DEFLATE compresses the repetitive palette indices far better. Palette quantisation is what tools mean when they advertise “up to 80 % smaller PNGs”. It is excellent for screenshots, logos, diagrams and interface graphics, which rarely use many colours to begin with, and it keeps transparency because the palette entries can carry alpha values.

The cost shows up in photographs and smooth gradients, where 256 colours are not enough and the quantiser has to approximate. Dithering – scattering pixels of two nearby palette colours – hides the banding to some extent but adds visible noise. If you quantise a photograph and the file is still large, you have chosen the wrong format: a lossy WebP or JPEG would be both smaller and better looking.

Why the same setting gives wildly different savings

People are often surprised that one image shrinks by 70 % and the next by 3 % at the same setting. Three factors explain most of the variation.

  1. How compressed the source already was. A JPEG saved at quality 60 contains little that a second pass can remove; re-encoding it at quality 80 may even make it larger because the encoder now has to represent the existing artefacts faithfully. Compressors that report the output honestly will tell you when this happens.
  2. Image content. Noise, fine texture and gradients are expensive in every format. Flat colour, repeated patterns and sharp but simple shapes are cheap.
  3. Metadata. Photos straight from a camera or phone carry EXIF blocks, embedded thumbnails and colour profiles that can add tens of kilobytes. Stripping them is lossless as far as the pixels are concerned, which is why removing metadata is part of nearly every compression workflow – and why you should think about whether you need to keep EXIF orientation or camera information before you strip it.

Target file sizes

Some destinations impose hard limits: a form that rejects uploads over 200 KB, an email signature image that should stay under 50 KB. A target-size mode works by trying a quality value, measuring the output, and adjusting up or down in a bounded number of steps until the output lands just under the limit. Because quality has an upper bound and dimensions are fixed, a target can be impossible – a 6000×4000 photo will not fit in 50 KB at any acceptable quality. A trustworthy tool reports that instead of silently delivering a ruined image, and the fix is to resize first and compress second.

A before and after example

Take a typical 12-megapixel phone photo: 4032×3024 pixels, saved by the camera as a JPEG of roughly 3–4 MB. The arithmetic below is illustrative – exact sizes depend on the scene – but the proportions hold for most photographs:

Step Dimensions Typical size
Original from the phone 4032×3024 3–4 MB
Re-encoded at quality 80, same size 4032×3024 1.5–2 MB
Resized to 1600 px wide, quality 80 1600×1200 250–400 KB
Resized to 1600 px wide, WebP quality 80 1600×1200 180–300 KB
Original from the phone: 3.5 MB; Quality 80, same dimensions: 1.8 MB; 1600 px wide, JPEG quality 80: 330 KB; 1600 px wide, WebP quality 80: 240 KBOriginal from the phone3.5 MB100%Quality 80, same dimensions1.8 MB51%1600 px wide, JPEG quality 80330 KB1600 px wide, WebP quality 80240 KB
The same 12-megapixel photo at each step (illustrative midpoints of the table above). Re-encoding alone roughly halves the file; resizing to the displayed width removes most of the remaining bytes.

The quality setting alone roughly halves the file. Resizing to the size the page actually displays removes about 85 % of the pixels and does far more. That is why a 200 KB target is easy after resizing and out of reach before it.

A practical workflow

  1. Decide what the image is: photo-like (continuous tones) or graphic-like (flat colours, text, sharp edges).
  2. Photo-like content: use a lossy format (WebP for the web, JPEG when compatibility matters), start at quality 80, compare, and lower it until artefacts appear, then step back up.
  3. Graphic-like content: use PNG with palette quantisation or lossless WebP; check edges and gradients after quantising.
  4. Resize to the largest size the image will actually be displayed at before compressing – dimension reduction saves more bytes than any quality setting.
  5. Strip metadata unless you need it, and keep the original file somewhere safe. Compression is a one-way street.

Try it: Image Compressor for photos, or PNG Compressor for screenshots and graphics.

The compressors on this site show the original size, the new size and the real percentage change for every file, and they let you keep the original when the output would be larger. That is deliberate: the goal is not the biggest headline saving but a result you can trust.

Sources and further reading

About the author

HelpMeJPG editorial teamEditorial team

The people who build and maintain the HelpMeJPG tools. Guides are written from the tools' own behaviour and the standards they implement, and are revised whenever a tool changes.