How Image Compression Works
A 6 MB photograph can usually be turned into a 600 KB photograph that looks the same on a screen. That sounds like a trick, and understanding why it is not explains almost every practical decision about image files — which format to pick, where to set the quality slider, and why some files refuse to get smaller no matter what you do.
This guide covers what compression actually removes, the difference between the two families of technique, how the numbers on a quality control relate to what you see, and where the savings really come from.
What an uncompressed image costs
Start with the raw arithmetic, because it makes everything after it obvious.
An image is a grid of pixels, each needing three bytes for red, green and blue. So the storage a picture wants before anything clever happens is just width × height × 3:
| Dimensions | Raw size |
|---|---|
| 800 × 600 | 1.4 MB |
| 1920 × 1080 | 5.9 MB |
| 4000 × 3000 (12 MP) | 34 MB |
| 8000 × 6000 (48 MP) | 137 MB |
A 12-megapixel phone photo would be 34 MB with no compression at all, and it arrives as a 3 MB JPEG. That tenfold reduction is not the camera being clever about your particular picture; it is the default behaviour of a format designed in the late 1980s around a specific observation about human eyesight.
Notice too what that table implies about priorities. Halving both dimensions quarters the raw size before any compression is applied. Pixel count is the dominant term, which is why resizing an oversized image saves far more than any quality setting will — a point the sizing guide develops properly.
Lossless: finding the redundancy
The conservative approach keeps every pixel exactly and looks for structure to exploit.
Consider a screenshot with a solid grey toolbar. Storing four hundred identical grey pixels individually is wasteful when you could store "this grey, four hundred times". Real lossless image compression is more sophisticated than that — PNG applies a filtering step that stores each pixel as the difference from its neighbours, turning a smooth gradient into a run of small numbers, then compresses the result with DEFLATE — but the principle holds: find repetition, describe it once.
The W3C specification for PNG, now in its third edition, describes the format's purpose as "lossless, portable, well-compressed storage", with filtering and compression that "preserve all information". Decode a PNG and you get back precisely the pixels that went in.
The catch is that this only works when there is redundancy. A screenshot, a logo, a diagram, a chart — large flat areas, hard edges, few distinct colours — compresses beautifully. A photograph of leaves does not: every pixel differs slightly from its neighbours, there is no pattern to exploit, and a lossless encoder ends up storing something close to the full 34 MB. This is the entire reason photographs are not distributed as PNG.
It is also why the quality slider does nothing to a PNG. There is no quality dial on a process that is defined by keeping everything — which is exactly what the compressor tells you when it detects a PNG that will stay a PNG, and why it offers to switch the output to WebP instead.
Lossy: discarding what you will not miss
The aggressive approach accepts that the decoded image will not match the original, and spends its effort on making the difference invisible.
Two facts about human vision make this possible. We are considerably more sensitive to changes in brightness than to changes in colour. And we are poor at noticing fine, high-frequency detail — rapid variation across a few pixels — compared with the broad shapes and edges that carry the meaning of a picture.
JPEG, which MDN describes as "the most widely used lossy compression format for still images", exploits both:
Colour gets less space than brightness. The image is converted from RGB into a brightness channel plus two colour channels, and the colour channels are then stored at reduced resolution — often one colour sample for every four pixels. This is chroma subsampling, and it throws away three quarters of the colour information before compression proper has even started. On a photograph you will not see it. On red text against a blue background, you will.
Detail is sorted by importance and the least important is dropped. The image is divided into small blocks, and each block is transformed with a discrete cosine transform into a set of frequency coefficients — one describing the block's average tone, the rest describing progressively finer variation within it. Those coefficients are then divided by a quantisation table and rounded, which sends many of the high-frequency ones to zero. Zeros compress to almost nothing.
The quality setting is that quantisation table. Turning quality down multiplies the divisors, rounding away more coefficients. It is not a blur and not a resize; it is a decision about how much of the fine detail to keep. Which is why the artifacts have their characteristic look: blocking where the 8×8 grid becomes visible in smooth areas, and ringing around hard edges where the discarded high frequencies were doing the work.
WebP and AVIF apply the same principle with better machinery — MDN describes WebP's lossy mode as "predictive coding based on the VP8 video codec" — and get more compression at the same apparent quality as a result.
Why the loss is usually invisible
The reason an 80%-quality JPEG looks identical to its source is not that little was removed. A great deal was removed. It is that what was removed was chosen specifically to be the part you are worst at seeing.
That framing also predicts where lossy compression fails, which is more useful than knowing where it succeeds:
- Screenshots and text. Hard edges are exactly the high-frequency content the transform discards, so text acquires a visible halo.
- Line art and logos. Same reason, plus flat colour that would have compressed losslessly for free.
- Large smooth gradients. A sky or a soft studio background shows banding and blocking, because there is little detail to hide the artifacts behind.
- Images destined for editing. Every save re-quantises, and the damage accumulates.
Photographs of textured, detailed scenes are the ideal case — which is exactly what the format was designed for.
Where the savings actually come from
Four independent levers, in rough order of how much they typically buy:
1. Fewer pixels. Quadratic, and almost always the biggest win. A 4000-pixel-wide photo shown in an 800-pixel column carries twenty-five times the pixel data it can display.
2. A better format. Free in visual terms, since you are changing the encoder rather than the picture. Google's published figures put WebP at 25–34% smaller than comparable JPEG at equivalent SSIM quality, and 26% smaller than PNG for lossless images. MDN's guide puts AVIF ahead again — a median 50% reduction against JPEG where WebP manages 30% on the same set.
3. Quality setting. Substantial from 100% down to about 80%, then rapidly diminishing while the artifacts grow.
4. Metadata. A camera JPG can carry tens of kilobytes of EXIF, and sometimes an embedded thumbnail and a colour profile. Irrelevant on a 3 MB file; material on a 40 KB icon, and worth removing for privacy reasons regardless.
The practical consequence is an order of operations. Crop to what you are actually showing, resize to the dimensions you will actually display, convert to an efficient format, and only then reach for the quality slider. Most people do it backwards, drag quality to 40%, and get a small ugly file where a resize would have given them a small clean one.
Compressing twice, and other traps
Generation loss is real but often overstated. Re-encoding a lossy file re-quantises it, so damage accumulates: the second save discards detail from an image that has already lost some. In practice one extra round trip at high quality is close to harmless, while repeatedly saving at middling quality visibly degrades a picture. The rule that matters is to keep an original — edit from the source, export once.
Re-compressing an optimised file usually makes it larger. This surprises people. The artifacts introduced by the first compression are themselves high-frequency detail, so the second encoder faithfully spends bytes preserving the first encoder's damage. ToolForge's compressor has a safeguard on by default for this: when the output would be bigger than the input it keeps the original bytes and marks the file "Already optimised" rather than handing you a worse, larger copy.
Lossless-to-lossy is one-way. Converting a JPEG to PNG does not restore anything; you get a lossless copy of a lossy image, typically several times larger with no improvement whatsoever. This is one of the most common wasted operations in image work.
Animated GIFs are a different problem. Canvas-based compression re-encodes a single frame, so an animation comes out as a still — the tool warns about this explicitly rather than silently destroying the animation.
Doing it
Everything above is background for four practical decisions, each with its own guide:
Just compress this image. The step-by-step version, including which of the presets to use and when target-size mode is the right choice.
Keep it looking good. Where the quality thresholds actually are for photographs, screenshots and graphics, and what "without losing quality" can honestly mean.
Choose a format. JPG, PNG and WebP compared with a decision table, plus where AVIF fits.
It is still too big. The specific reasons — a PNG that stayed a PNG, dimensions rather than quality, an upload limit measured differently than you think.
All of it runs in the compressor on your own machine: files are decoded, re-encoded and measured in the browser, and even the background worker script is served from this site rather than a third-party CDN, so nothing about your photographs reaches a server.
Image Compressor
Compress JPG, PNG, WebP by quality or target file size. It runs in your browser, so the files never leave your machine, and there is nothing to install or sign up for.
Try the Image CompressorFrequently asked questions
Does compressing an image always reduce quality?
No — it depends which family you use. Lossless compression (PNG, WebP lossless) reconstructs the original pixels exactly, so quality is untouched and the saving comes from removing redundancy. Lossy compression does discard image data permanently, though at high settings the difference is genuinely hard to see on a photograph.
Why did compressing my PNG barely change the file size?
Because quality settings only apply to lossy formats, and PNG is not one. A PNG that stays a PNG can only shrink by having fewer pixels or fewer colours. Converting it to WebP is usually the answer — WebP has a lossless mode that Google measures at 26% smaller than PNG, and a lossy mode that goes much further.
What quality setting should I use?
Around 80% for photographs on the web, which is where the compressor's Web preset sits, and 90–95% for anything you might print or edit later. Below about 60% artifacts become visible in skies and gradients. Screenshots and line art want a lossless format instead of a lower number.
Is WebP better than JPEG for everything?
For file size at a given visual quality, essentially yes, and it also handles transparency and animation. The remaining arguments for JPEG are compatibility with very old software and the fact that some print and camera workflows expect it. For the web, WebP is the better default.
How small can I make an image?
There is no fixed floor, but useful targets are under 200 KB for a large web image and under 100 KB for anything above the fold. Getting there is mostly about dimensions: pick the size you actually display, then compress. Chasing a very small number with the quality slider alone produces a visibly damaged picture.
The short version
Compression works by exploiting either redundancy in the data or the limits of your eyesight, and knowing which one a format uses tells you everything about how it will behave. Lossless formats keep every pixel and only shrink pictures that contain repetition, which is why screenshots suit them and photographs do not. Lossy formats discard the detail you are worst at noticing, which is why an 80%-quality photograph looks untouched. And whichever you choose, the largest saving available is almost always the one people try last: showing fewer pixels.
Tools that go with this
Each one is here for a specific reason rather than because it is in the same category.
Image Format Converter
Convert between JPG, PNG, WebP, AVIF, and HEIC
Changing format is usually a bigger saving than changing quality, and this is where that happens.
Image Batch Resizer
Resize multiple images at once online for free
For the saving most oversized images actually need — fewer pixels, not harder compression.
Image Metadata Remover
View and remove EXIF, GPS, and hidden data from images
Shows what non-image data a file is carrying, which on a camera JPG can be tens of kilobytes.
Image Cropper
Crop and resize images with custom aspect ratios
Cropping removes pixels you were never showing, which is the cheapest saving of all.
Social Media Image Resizer
Resize one image to every social platform size at once
Platform presets, for when the target dimensions are dictated rather than chosen.
Related articles
How to Compress an Image
Compress JPG, PNG or WebP files in your browser: which preset to use, when to set a target size in KB, and the order of operations that saves the most.
What Is the Difference Between Lossy and Lossless Compression?
Lossless keeps every pixel; lossy discards what you cannot see. What each one actually promises, why lossless is not "better quality", and which to pick.
JPG vs PNG vs WebP: Which Should You Use?
A decision table plus the published figures: WebP is 25–34% smaller than JPEG and 26% smaller than PNG. When each format still wins, and where AVIF fits.
How to Compress Images Without Losing Quality
Truly lossless compression, and visually lossless compression, are different things. Which to use per image type, and where the quality thresholds actually sit.
Why Your Image Is Still Too Large After Compressing
Six reasons compression did not shrink your file: a PNG that stayed a PNG, dimensions rather than quality, an already-optimised source, or a lying upload limit.
What Image Size Should You Use on a Website?
Pixel dimensions, file size and DPI are three different things, and only two of them matter on the web. The sizes to use, and why 300 DPI is meaningless here.
Image Optimization Best Practices
The nine things that actually make images fast, in order of impact — right dimensions, right format, lazy loading everything except the one image you must not.
CR3 vs JPG: What Is the Difference?
CR3 keeps your sensor data, JPG keeps a finished picture. What each one costs you in card space, editing freedom and compatibility, and when to shoot which.
Sources
- Image file type and format guide
MDN Web Docs · Technical documentation · accessed 7 September 2026
Cited for: JPEG as the most widely used lossy format and DCT-based, WebP lossy as VP8 predictive coding, and AVIF's median 50% versus WebP's 30% compression on the same JPEG set
- WebP: A new image format for the Web
Google · Official documentation · accessed 7 September 2026
Cited for: WebP lossy 25–34% smaller than JPEG at equivalent SSIM, and lossless 26% smaller than PNG
- Portable Network Graphics (PNG) Specification (Third Edition)
W3C · Standards organisation · published 24 June 2025 · accessed 7 September 2026
Cited for: PNG as lossless, well-compressed storage whose filtering and compression preserve all information
About the author
Builder and maintainer, ToolForge
Started ToolForge in May 2026 and has built and maintained it since, writing every tool on the site and the documentation that goes with each one.
Part of
Image Compression & FormatsWhy lossy compression works, which format to use, what image size a web page actually needs, and why a file is still too big after compressing it.
Browse all image tools