designwithfocus

Page speed & performance

Image Compression and Its Types: Lossy and Lossless

By Design With Focus Team 6 min read
A photo split into a lossy file and a lossless file with format labels

Short answer

Image compression is either lossy, which discards data to make a smaller file, or lossless, which keeps every sample so the original can be rebuilt. MDN assigns JPEG to lossy photos, PNG and GIF to lossless images, and WebP and AVIF to both modes. The W3C PNG specification defines lossless as reconstruction that is exact, bit for bit. Percentage claims below are MDN's wording, not a new measurement.

Last verified against the sources listed below.

Key takeaways

  • Lossy compression throws away data. Lossless compression can rebuild the original exactly.
  • MDN calls JPEG lossy and says it has no alpha channel. PNG is lossless and can have transparency.
  • GIF is lossless LZW on an indexed palette of up to 256 colors.
  • WebP and AVIF each support a lossy mode and a lossless mode.
  • MDN's size comparisons are its summaries. This guide does not add a savings percentage.

Image compression and its types come down to two families. Lossy compression discards data to shrink the file. Lossless compression keeps enough data to rebuild the original exactly. The format you pick is usually one of those two, and a few formats can do either.

Page speed is where the smaller file shows up, as fewer bytes to download. The type of compression is a separate decision from the speed score.

What are the two types?

Lossy throws information away. Lossless does not.

Type What is kept What you notice Formats MDN assigns
Lossy An approximation Smaller files, possible blur or fringes JPEG. WebP and AVIF in lossy mode
Lossless Enough to rebuild the original Larger than a lossy export of the same picture PNG, GIF. WebP and AVIF in lossless mode

MDN’s image format guide says compression can be lossy, discarding data for a much smaller file, or lossless, reproducing the original exactly. It prefers lossless encoding for screenshots, diagrams, logos, and line art.

Photographs can usually tolerate lossy compression. WebP and AVIF can be either, as an encoder setting. JPEG is lossy, and PNG is lossless.

The W3C PNG specification defines lossless as a method that permits reconstruction of the original data exactly, bit for bit. PNG uses filtering that is reversible, then a deflate-style compression from the LZ77 family. The spec’s design goals include losslessness and a patent-free replacement for GIF, plus an optional alpha channel. That is the formal version of the lossless row.

Which common formats are lossy?

JPEG is the lossy format MDN names first. WebP and AVIF can join it.

MDN says JPEG is the most widely used lossy format for still images, and that it is particularly useful for photographs. Applying it to diagrams or charts can look bad, because those images need sharp edges.

The compression is based on the discrete cosine transform. True color is 8 bits per component, with no indexed mode and no alpha channel. The file people call a JPEG is the JFIF packaging of that data.

Lossy WebP uses predictive coding based on the VP8 video codec. MDN says lossy WebP images are on average 25 to 35 percent smaller than JPEG images at visually similar compression levels. That is MDN’s average, not a result for every picture.

AVIF stores AV1 bitstreams in a HEIF container. The AVIF specification, version 1.2.0, dated 16 October 2025, specifies that storage and the profiles that constrain it. It supports HDR, wide color, transparency, and multi-layer images.

MDN says lossy AVIF is around 50 percent smaller than JPEG at visually similar levels, and that you should offer a fallback because support is newer. The specification itself does not print that percentage. The percentage stays attributed to MDN.

What a JPG is goes further into that one lossy format.

Color encoding is not the same choice as lossy versus lossless. The ICC sRGB entry defines sRGB as IEC 61966-2-1:1999, a colorimetric RGB space with 8-bit encoding in common use. A JPEG and a PNG can both be tagged sRGB. The tag does not tell you whether the compression discarded samples.

Which common formats are lossless?

PNG and GIF are the lossless pair MDN contrasts with JPEG. WebP and AVIF have lossless modes too.

MDN says PNG uses lossless compression, supports higher color depths than GIF, and has full alpha transparency. The W3C spec matches that: indexed color, greyscale, and truecolor, sample depths from 1 to 16 bits, and optional alpha. Browsers have supported PNG for a long time. MDN still notes that WebP and AVIF can compress further, with less historical support.

GIF, introduced by CompuServe in 1987, uses LZW to compress 8-bit indexed color. Each pixel indexes a palette whose length is a power of two, up to 256 colors.

MDN says the relevant LZW patents had expired as of 7 July 2004, so the format may be used freely. GIF can animate and can interlace. For a still image that needs more than the palette, MDN says to prefer PNG.

Lossless WebP uses substitutions for repeating data. MDN says lossless WebP images are typically 26 percent smaller than the same images in PNG. The table lists Huffman, LZ77, or color-cache codes for that path.

Maximum dimensions on that page are 16,383 by 16,383 pixels. The 26 percent figure is MDN’s typical case, not a guarantee for one export.

AVIF’s lossless mode is the other setting on a format that also has a lossy mode. MDN says to provide a WebP, JPEG, or PNG fallback. The Alliance for Open Media document is the syntax. It is not a savings chart.

How do you choose without inventing a savings number?

Match the type to the picture, then compare the files you actually export.

Use JPEG, or lossy WebP or AVIF, for photographs when a smaller file matters more than exact pixels. Use PNG or lossless WebP for interface art, type, and screenshots. Use GIF when you specifically need a simple indexed animation and you can live with the palette. Keep a fallback for AVIF, as both MDN and the need for broad support suggest.

MDN also says the older formats have wider historical support, and the newer ones are popular because the browsers that lack them are disappearing. Support is a reason to keep a second file. It is not a percentage.

The image compressor compresses a JPG, PNG, or WebP in the browser. It applies a type you already chose. It does not invent a savings rate, and it does not replace the fallback file.

Frequently asked questions

When should a screenshot stay lossless?

MDN says screenshots, diagrams, logos, and line art should prefer lossless encoding, because blur and fringes around text are easy to see. Photographs can usually tolerate lossy compression, because the discarded detail is harder to notice. JPEG is the lossy fallback it names for photographs. PNG is the lossless choice for screenshots and for any image that needs transparency, since JPEG has no alpha channel.

Can WebP or AVIF be lossless?

Yes. MDN's WebP table lists lossless compression using Huffman, LZ77, or color-cache codes, and lossy compression using VP8. Its AVIF table says compression is lossy and lossless. The AVIF specification stores AV1 images in a HEIF file and supports transparency through an auxiliary bitstream. Choosing the format name does not choose the mode. The encoder setting does. A lossless WebP is still WebP, and a lossy AVIF is still AVIF.

Does GIF count as lossless if the colors look worse?

The compression step is lossless. MDN says GIF uses LZW to compress 8-bit indexed color, and each pixel is an index into a palette of up to 256 colors. Reducing a full-color photo to that palette happens before compression, and dithering can look poor. Once the indexed image exists, LZW packs it without a further lossy step. Prefer PNG when you need more colors than the palette.

Are the percentage savings on MDN a guarantee?

No. MDN says lossy WebP is on average 25 to 35 percent smaller than a visually similar JPEG, and lossless WebP is typically 26 percent smaller than the same image as PNG. It says lossy AVIF is around 50 percent smaller than JPEG at similar levels. Those are MDN's summaries. They are not a promise for one file, and this guide adds no percentage of its own.

Does a smaller file replace a fast server?

It removes bytes from the download. MDN's performance docs treat image weight as part of loading, and the format guide says older formats are widely supported while WebP and AVIF compress more. A page can still be slow for other reasons. Compress the image that is actually large, keep a fallback where a new format is not supported, and do not expect the format label alone to describe the whole page.

Sources