How image compression works
Every format on this site falls into one of two camps: lossless, which keeps every pixel exact, and lossy, which throws away detail you are unlikely to notice.
Two families, one goal
An uncompressed image is just a grid of pixel values, each one a set of color numbers. Stored raw, that grid is large: a 12 megapixel photo at 24 bits per pixel is around 36 megabytes before any compression. Every image format's job is to represent that same grid in fewer bytes, and every format does it with one of two fundamentally different strategies: lossless, which finds and removes redundancy without changing the result, or lossy, which deliberately discards information the format's designers decided you would not miss.
Lossless compression: finding redundancy
Lossless compression, used by PNG, GIF, and BMP's compressed variants, works by spotting patterns and repetition and encoding them more compactly, the same general idea behind zip files. PNG specifically uses DEFLATE: it predicts each pixel from neighboring pixels and then compresses the difference, which works well when an image has large flat areas or repeating patterns and less well on photographic noise and gradients. Decode a losslessly compressed file and you get back the exact original pixels, byte for byte. Nothing is guessed or approximated.
GIF takes a different lossless route: it limits an image to a palette of at most 256 colors and then compresses the resulting index values. That is fine for simple graphics and icons but produces visible color banding on photographs, which is why GIF has mostly been replaced by PNG for still images and survives mainly for its animation support.
Lossy compression: spending bits where they matter
Lossy compression, used by JPG, and by the lossy modes of WebP, AVIF and HEIC, works differently: it deliberately discards information, choosing to discard the information human vision is least likely to notice. The classic example is JPG: it transforms 8 by 8 blocks of pixels into frequency data using a discrete cosine transform, then quantizes that data more aggressively at high frequencies (fine detail) than at low frequencies (broad shapes and tone), because the eye is more sensitive to broad tonal changes than to fine high-frequency texture. It also uses chroma subsampling, storing color information at lower resolution than brightness information, since human vision resolves brightness far more sharply than color.
Newer lossy formats build on the same core idea with better tools. WebP's lossy mode is derived from the VP8 video codec, AVIF is derived from the AV1 video codec, and HEIC is derived from HEVC (H.265). Video codecs are built to compress a sequence of similar frames extremely efficiently, and reusing that machinery for a single still frame gives these formats noticeably better compression than JPG's much older approach, at the same visual quality.
The quality dial
Every lossy format exposes a quality setting, sometimes as a percentage, sometimes as a quantization level, that controls how aggressively it discards information. A higher quality setting keeps more detail and produces a larger file; a lower one discards more and produces a smaller file. There is no universal correct value: the right setting depends on the image and how it will be viewed. That is exactly the control this site's image compressor tool gives you directly over a file, without needing to change its format at all.
Picking a strategy
Use lossless formats for anything you will edit repeatedly, anything that must be pixel-perfect (screenshots, diagrams, scanned text, logos), and anything with sharp edges or flat color. Use lossy formats for the final delivery of photographs and other continuous-tone images, where a well-chosen quality setting is visually indistinguishable from the original but a fraction of the size. Most real workflows use both: edit and archive losslessly, export losslessly, and export to a lossy format is fine, and export to a lossy format only for the final version that actually gets published or shared.
Try it now
Ready to convert? These converters run entirely in your browser, free and with no upload:
Related tools
Frequently asked questions
Is lossless compression always better than lossy?
Not for delivery. Lossless guarantees exact pixels but produces much larger files for photographs. Lossy compression, at a sensible quality setting, looks the same to the eye while being a fraction of the size, which is usually what actually matters for a website or a shared photo.
Why do modern formats like AVIF and WebP compress better than JPG?
They are built on newer video codecs (AV1 and VP8 respectively) that use more sophisticated prediction and encoding techniques than JPG's decades-old discrete cosine transform approach, so they need fewer bits to reach the same visual quality.
Does resizing an image compress it?
Resizing reduces the pixel count, which reduces file size, but it is a separate operation from compression. This site's image resizer and image compressor are deliberately two different tools so you can use either one independently, or both together.