All tools

How image compression works

A photo straight from a modern phone is millions of pixels, yet the file is a few megabytes. Something has clearly been squeezed out. Knowing what is removed, and when, explains almost every decision about image settings: why a screenshot is better as PNG, why re-saving a JPG makes it worse, and why shrinking the pixel size is the strongest lever for reaching a file-size limit.

The size of the raw picture

An uncompressed picture stores red, green and blue values for every pixel, at one byte each. A 12-megapixel phone photo of 4032 × 3024 pixels contains 12,192,768 pixels. At three bytes per pixel that is 36,578,304 bytes, about 36.6 MB, before any format is applied. Compression is what turns that into a file you can email.

Two families: lossless and lossy

How JPG does it

JPG is the classic lossy photo format. The JPEG standard (ITU-T T.81) describes the main steps, and they are worth knowing because each one corresponds to a visible effect.

  1. Split into blocks. The image is divided into blocks of 8 × 8 samples, and each block is processed on its own. Those blocks are why heavily compressed JPGs show a visible grid.
  2. Transform. Each block goes through a discrete cosine transform (DCT), which re-expresses the 64 values as a mixture of smooth patterns, from gentle gradients to fine detail. This step is invertible and loses nothing.
  3. Quantize. This is the lossy step. The encoder uses a quantization table of 64 values that the coefficients are divided by and rounded. Fine-detail coefficients are divided by larger numbers, so many become zero. In most encoders, the “quality” slider works by scaling this table.
  4. Entropy-code. The long runs of zeros and small numbers that result are packed with Huffman coding, a lossless step. The standard also allows an arithmetic-coding option.

The JPEG family also treats colour separately from brightness: the JFIF part of the standard describes converting between RGB and YCbCr and upsampling the colour channels, because the picture can carry less colour detail than brightness detail without looking different. Together, these steps explain the JPG look. Text and sharp edges produce ringing and smudges, because abrupt edges need fine-detail coefficients that quantization crushes. Smooth skies and skin survive well.

How PNG does it

PNG is lossless, and its specification says so plainly: filtering and compression should preserve all information. It works in two stages. First, each row of pixels is filtered: the W3C specification defines five filter types, including Sub, Up, Average and Paeth, which replace each byte with its difference from a prediction based on neighbouring pixels. Filtering is reversible and exists purely to make the data more compressible. Second, the filtered bytes are compressed with deflate.

Flat colours, screenshots and diagrams compress superbly this way, because neighbouring pixels are identical, so the differences are mostly zero. Photographs do not, because noise and texture make every pixel slightly different. This is why a photo saved as PNG is typically several times larger than the same photo as JPG.

PNG also supports indexed colour, where the file stores a palette and each pixel is just a reference into it. If you reduce an image to fewer colours first, PNG gets much smaller with little visible change, which is the approach on our PNG size pages. Be aware that this step is lossy even though PNG itself is not: the loss happens when the colours are reduced, before PNG sees the data.

How WebP does it

Google’s documentation describes WebP as two codecs in one format. Lossy WebP borrows from video compression (it is based on VP8 key-frame coding): instead of treating each block alone, it predicts each block from pixels already decoded next to it and encodes only the difference. It adapts quantization to different regions of the image, and uses arithmetic coding, which Google credits with 5 to 10 percent compression gains over the Huffman coding used in JPEG. Lossless WebP uses spatial prediction, colour transforms, palettes and LZ77-style back-references.

The results Google reports: lossless WebP images 26% smaller than PNGs, and lossy WebP 25 to 34% smaller than comparable JPEGs at equivalent quality. WebP also supports transparency in both modes, including lossy colour with a lossless alpha channel, a combination PNG cannot offer.

Why quality is the weakest lever

When a form says “maximum 100 KB”, the instinct is to drag the quality slider down. That works, but badly. Three things shape a lossy file’s size, in this order of strength:

  1. Pixel dimensions. Halve the width and height and you have a quarter of the pixels to encode. Size drops sharply, and on a typical screen nobody notices if the picture is shown at its smaller size.
  2. Format. WebP or JPG for photos, PNG for flat graphics.
  3. Quality. Past a certain point, each step down saves less and costs more visible damage.

That is why the exact-size tools on this site search for the combination of dimensions and quality that fits your limit, instead of simply lowering quality until it works. In our test, a 12 MP phone photo kept its full 4032 × 3024 pixels at JPEG quality 80 and still came in under 1 MB, while a limit of 50 KB needed the picture scaled to roughly 1,200 pixels wide. File size also depends on the picture itself: a busy photograph of leaves and a plain wall at the same settings can differ many times over, which is why a quality number alone cannot predict a file size.

Generation loss: why re-saving hurts

Every time a lossy file is opened and saved again, the quantization step runs once more on data that was already approximated. Errors accumulate, and edges and blocks get steadily worse. This is called generation loss. The remedies are simple: edit from the original, export once at the end, and avoid passing the same JPG through several apps and chat services. If you only need to remove location data, use the metadata remover, which does not recompress the picture.

Choosing from what you now know

PictureFormatWhy
PhotoJPG or WebPSmooth gradients and noise suit lossy transforms
Screenshot, UI, textPNG or lossless WebPFlat areas and sharp edges compress losslessly and stay crisp
Logo with transparencySVG, else PNGVectors scale without pixels
Photo with transparencyWebPLossy colour with lossless alpha

For the decision in practical terms, see JPG, PNG or WebP. To apply what you have learned, try the image compressor, which shows a before and after view as you move the quality slider.

Sources

Checked 6 December 2026. Limits and policies change, so the provider’s own page always wins.

Frequently asked questions

What is the difference between lossy and lossless compression?

Lossless compression stores the same pixels in less space and can be reversed exactly. Lossy compression discards detail that is least visible, which makes files much smaller but cannot be undone.

Why does my JPG look worse every time I save it?

Each save re-applies lossy quantization to already approximated data. The errors accumulate. Always edit from the original and export once.

Is PNG always lossless?

The PNG format is. But reducing the number of colours before saving is lossy, and that is how tools make PNGs far smaller.

Why does shrinking the pixel size reduce file size more than lowering quality?

Halving width and height leaves a quarter of the pixels to store, whereas lowering quality only coarsens the values for the same number of pixels.