designwithfocus

Page speed & performance

What Is Image Compression? Lossy, Lossless and Why Files Shrink

By Design With Focus Team 6 min read
One photograph shown as a large file and a smaller compressed file

Short answer

Image compression is a way to store a picture in fewer bytes, either by packing the same pixels or by throwing some detail away. Lossless methods rebuild the original bits. Lossy methods keep an approximation the eye will accept. JPEG is a common lossy choice for photos. PNG is a lossless choice. WebP and AVIF can do either job in a smaller file, and the quality number you pick is not the same across formats.

Last verified against the sources listed below.

Key takeaways

  • web.dev describes a lossy step that drops pixel data and a lossless step that packs what remains.
  • The PNG specification defines lossless compression as rebuilding the original data exactly, bit for bit.
  • MDN calls JPEG a lossy choice for still images and PNG the choice when you need a more exact copy.
  • A JPEG-style quality control is often a number from 1 to 100, and the same number means something else in WebP.
  • JPEG XL's own site describes typical compression ratios of 20:1 to 50:1 for that codec, not for every format.
  • JPEG AI is a learning-based image coding standard. The JPEG page does not call it neural compression.

What is image compression is a file question, not a design-tool question. You start with pixels and end with a smaller sequence of bytes. Sometimes those bytes can rebuild the pixels exactly. Sometimes they rebuild a close version.

That difference is why a screenshot and a photograph should not share one setting. Page speed feels the file size.

JPEG is one format that gets smaller by discarding detail. The sections below separate the meaning, the steps, and the formats.

What does image compression mean?

Image compression means encoding a picture so the file takes fewer bytes than the raw pixels. The meaning splits into lossless and lossy.

web.dev’s compression article says some data, such as a program, cannot lose a bit without changing meaning. Images, audio, and video can often use an approximation. The eye is less sensitive to some color detail, so an encoder can spend fewer bits there.

Lossless compression keeps a path back to the same bits. The PNG specification defines lossless as a method that permits reconstruction of the original data exactly, bit for bit. Lossy compression does not make that promise. It keeps a picture that is meant to look close enough.

How does image compression work?

A typical pipeline has an optional lossy step, then a lossless packing step. The first step deletes information. The second step only packs what is left.

web.dev describes those two steps in that order. The lossy filter is optional, and the algorithm depends on the format. GIF, PNG, and JPEG differ by which steps they run.

There is no single setting for every picture. Detailed art may skip the lossy step, and a large photo may accept a stronger one.

PNG is the lossless pattern in the spec. Each scanline is filtered, which prepares it for compression, and then the filtered scanlines are compressed. The spec says filtering and compression should preserve all information. The method it names is deflate, in the LZ77 family.

Lossy WebP, on Google’s compression page, uses block prediction, adaptive quantization, and entropy coding. The page says the lossy method follows the same prediction approach as VP8. That is a different machine from PNG’s filter-then-deflate path.

Which formats compress differently?

The format is the contract for what the file may throw away. Lossy or lossless is the first line of that contract.

Format What the docs say Typical job
JPEG MDN: lossy compression of still images Photographs
PNG W3C: lossless, with filtering then compression Interface art, exact copies, transparency
WebP Google: lossy and lossless, often smaller Photos or graphics when the client accepts it
AVIF MDN: lossy and lossless, plus animation and alpha Smaller photos, with a fallback
JPEG XL JPEG: lossy, lossless, and lossless JPEG recompression Delivery and a path off legacy JPEG

MDN’s image format guide says to prefer PNG for a more precise copy, and WebP or AVIF when you also want higher compression. AVIF is displayed only after the file has fully downloaded, because it has no progressive rendering.

JPEG XL adds animation, alpha, layers, and progressive coding, and it can losslessly transcode an existing JPEG.

MDN’s figure for AVIF is “around 50 percent smaller” than JPEG at visually similar levels. Google’s WebP page says WebP is typically 30 percent smaller than comparable JPEGs and PNGs. Quote those lines with their pages. They are not interchangeable measurements.

What is a compression level?

A compression level is the control a format exposes for that tradeoff, often called quality. It is not a universal scale.

web.dev says a lossy format such as JPEG typically offers a quality number from 1 to 100, and it names Photoshop’s Save for Web slider as one example of that control. The number drives the lossy and lossless algorithms inside that compressor. The page tells you to try more than one setting, because a lower number can still look fine while the file drops a lot.

The same note says quality levels are not comparable across formats. Quality 90 in JPEG is not quality 90 in WebP, and two encoders of one format can still disagree. Read the setting on the encoder you are using, then look at the picture.

The Image Compressor runs that comparison in the browser for a JPG, PNG, or WebP and shows the file size you got. It does not invent a correct level for every photo.

What is a compression ratio?

A compression ratio compares the size before compression with the size after it. There is no one ratio that every picture should hit.

The JPEG XL page is one place that prints a range. It says the codec is designed so you can balance criteria, and it lists a compression ratio typically from 20:1 to 50:1. That sentence is about JPEG XL. It is not a target for PNG screenshots or for a lightly compressed JPEG.

For a file you already exported, the useful comparison is the two sizes you can measure: the source and the output. web.dev’s point is the tradeoff between file size and the artifacts the lossy step introduced. A high ratio that ruins the subject is not a win.

What is image compression used for?

It is used to send pictures with fewer bytes, especially on pages where images dominate the download. The reason to care is the time those bytes take.

web.dev says images are often the element that becomes Largest Contentful Paint, so a shorter image download can improve that metric in lab data and field data. The same checklist prefers vector art when the picture is shapes rather than a photo, because vectors are not tied to one pixel size. For SVG, it says to minify the markup and to gzip it on the server.

Use lossless compression when the exact pixels matter, such as a screenshot of interface text or a logo you cannot blur. Use lossy compression for photographs, and compare two or three quality steps before you keep one. Strip metadata you do not need. Serve a file whose pixel size is close to the size on the page, which is a separate decision from the compression level.

Frequently asked questions

What is a compression factor?

A compression factor is another name for how hard the lossy step is pushed. It is not one number shared by every format. web.dev says a JPEG-style quality setting is typically a number from 1 to 100 controlling that compressor's algorithms. The same page warns that quality 90 in JPEG is not quality 90 in WebP. If a tool says factor instead of quality, read that tool's own scale rather than copying a number from a different format.

What is neural image compression?

The JPEG committee's JPEG AI page describes the first international image coding standard based on an end-to-end learning-based approach. Version 1, for human visual consumption, was published in 2025 as ITU-T T.840.1 and ISO/IEC 6048-1:2025. The page says the scope includes higher compression efficiency for people viewing images, and compressed-domain tasks such as classification, without a full pixel decode. That page does not use the phrase neural image compression. JPEG and PNG are older designs and are not that standard.

Does PNG ever throw pixels away?

Not in the compression step the PNG specification defines. PNG is specified as lossless. Filtering prepares each scanline, then compression packs the filtered scanlines. The spec says filtering and compression should preserve all information, and its glossary says lossless compression permits an exact, bit-for-bit reconstruction. You can still resize a PNG or reduce its color count before that step. Those edits change the pixels. The compressor itself is not what discarded them.

Why do AVIF and WebP get cited as smaller?

MDN says lossy AVIF images are around 50 percent smaller than JPEG images at visually similar compression levels, and that you should still offer a fallback because support is not universal. Google's WebP compression page says WebP images are typically 30 percent smaller than comparable JPEGs and PNGs. Those sentences come from different pages and different comparisons. They are not one lab result, and they are not a promise for every photo. Compare the file you actually export.

What does compression do to LCP?

web.dev notes that images are often candidates for Largest Contentful Paint, so a shorter download for the image can improve LCP in the lab and in the field. Compression is one part of that. The same checklist says to serve images at a display size close to their natural size, and to strip metadata you do not need, such as camera data. A tiny file that is the wrong crop still has to be the element that paints. Shrinking bytes does not change which element is largest.

Sources