The complete guide to image compression

How image compression works, lossy vs lossless, which format to pick, and the settings that make photos up to 90% smaller without visible loss.

· 6 min read

A photo straight from a phone is usually 2–5 MB. That is too big for most upload forms, slow on a website and wasteful in an email. Compression makes the file smaller by storing the same picture more efficiently, and, if you allow it, by dropping detail you would not notice. This guide explains how it works, which choices matter most, and the settings that make photos up to 90% smaller without a visible difference.

What image compression does

An uncompressed image stores three bytes for every pixel: one each for red, green and blue. A 12-megapixel photo is therefore about 36 MB of raw pixel data. Image formats store that data in far fewer bytes, in one of two ways.

Lossless compression

Lossless compression finds patterns and repetition and stores them compactly, the way a ZIP file does. When the image is opened, every pixel comes back exactly as it was. PNG works this way. It is ideal for screenshots, logos, diagrams and anything you will edit again, but photos stay large because their natural noise has few exact repeats.

Lossy compression

Lossy compression throws away detail your eyes are least sensitive to: very fine texture, and color detail, which we see in less detail than brightness. JPG, lossy WebP and AVIF work this way. For photos the savings are dramatic, up to 90%, but the discarded detail is gone for good. Saving a lossy file again loses a little more each time, so keep your originals and always compress from them.

What changesLosslessLossy
Pixels after savingIdentical to the originalClose to the original, not identical
Typical savings on photosSmallLarge, up to 90%
Best forScreenshots, logos, text, editing mastersPhotos and anything shown on a screen
FormatsPNG, lossless WebP, lossless AVIFJPG, WebP, AVIF
Saving againNo further lossEach save loses a little more

The four things that decide file size

1. Dimensions

File size grows with the number of pixels, so dimensions are the biggest lever. Halving the width and height leaves a quarter of the pixels. A 4000 × 3000 photo shown 1200 pixels wide in a blog post carries more than ten times the pixels anyone will see. Resize first, then compress. Our image resizer scales images to fit a width and height and keeps their proportions; smaller images stay as they are unless you ask to enlarge them.

2. Format

The same photo can differ several times over in size depending on the format. PNG photos are often 5–10 times larger than a good JPG. WebP is usually 25–35% smaller than JPG at the same visual quality, and AVIF is often around half the size of a JPG.

3. Quality setting

For lossy formats, the quality setting controls how much detail is discarded. Size does not change evenly: the step from 90 to 100 can nearly double a file with no visible gain, while the step from 75 to 85 is often hard to see. A quality of 75 is a good default for photos.

4. The encoder and metadata

Two files in the same format at the same quality can still differ in size, because some encoders are better than others. MozJPEG, for example, makes JPGs about 10% smaller than standard encoders, and every app still opens them. Files also carry metadata such as camera settings and, on phones, GPS location. It is rarely a large part of the file, but it can reveal where a photo was taken.

Choosing a format

FormatBest forTransparencyOpens everywhere?
JPGPhotos to share, upload or printNoYes
PNGScreenshots, logos, graphics, editingYesYes
WebPPhotos and graphics on websitesYesBrowsers yes; some apps and forms no
AVIFThe smallest files for websitesYesModern browsers yes; many apps no
GIFShort animations where nothing else is acceptedOn or off onlyYes

For a deeper comparison, read JPG vs PNG vs WebP and what AVIF is and when to use it.

Settings that work

ImageFormatQualityMax dimensions
Photo on a websiteWebP751920 px
Photo to email or shareJPG751600 px
Photo to print or editJPG85–90Original
Screenshot or graphicPNGDefault (palette reduction)Original
Form with a size limitJPGExact file sizeOriginal (shrink to fit if offered)

If you are unsure, compress at 75 and compare before and after. Our guide to image quality vs file size covers how to test results.

Compress JPEG imagesShrink JPG photos with MozJPEG at the quality you choose, on your own device.

Common mistakes

  • Compressing a compressed file. Each lossy save adds artifacts. Start from the original whenever you can.
  • Saving photos as PNG. PNG is lossless, so photos stay huge. Use JPG or WebP for photos, and compress PNG files that must stay PNG.
  • Enlarging small images. Upscaling adds pixels but no detail, so the file grows and the image blurs.
  • Forgetting transparency. JPG has none, so transparent areas turn white. Keep logos and cutouts as PNG, WebP or AVIF.
  • Converting animated GIFs. Converting a GIF to another still format keeps only its first frame. Compress it as a GIF instead to keep the animation.

How Graviton compresses images

Graviton runs the same open-source encoders the experts use: MozJPEG for JPG, libwebp for WebP, libavif for AVIF, OxiPNG with palette reduction for PNG, and a frame-by-frame palette encoder for GIF. They run as WebAssembly inside your browser, in parallel across your processor’s cores, so most photos are done in about a second.

Because the work happens on your device, your images are never uploaded. You can check this yourself: open your browser’s network tab while you compress, and nothing is sent. When you download, our servers receive only a one-way fingerprint of the image, which approves the download, keeps the free daily limit fair and is never stored.

Graviton saves every image without location, camera and other metadata unless you choose to keep some, such as the date taken, and converts every image it re-encodes to sRGB so it looks the same in every browser. HDR photos also keep their gain map, the brightness data HDR screens need. If the original is already smaller than any compressed version, you get your original image back, pixel for pixel, without its metadata. When a form sets a maximum, use the Exact file size goal, the homepage default, and Graviton finds the highest quality that fits.

Compress an image to any size in KBType the size you need in KB or MB and get the sharpest version that fits.