What compression throws away

Lossless, lossy and visually lossless, measured on a real photo: what each one keeps, what it costs, and when lossless is worth paying for.

8 min read

A round garden sieve rocking side to side. Sand falls through its mesh into a pile on the ground. The stones are too big for the holes and stay in the sieve.
A sieve keeps whatever is too big to fall through. Lossy compression makes the same call about detail, and the quality setting is the size of the holes.

TL;DR

A photo can't be stored losslessly for cheap: the smallest lossless copy of my test photo was 2.4 MB, 4.4 times its original JPEG. Resized to 1600 px and saved as JPEG at quality 75, it came to 232 KB and scored 81 on SSIMULACRA 2. Lossless is for screenshots, text and files you'll edit again.

I'm adding photo uploads to an app I built for a painting company. Staff walk a site, measure each wall and photograph it, and the photos go to the office for approval. They'll land in Vercel Blob, whose free plan includes 1 GB of storage.

Before writing the upload code, I did the arithmetic. My test photo is the flower from the JPEG XL project's test images: 3.4 megapixels, saved as a 547 KB JPEG. Stored as it is, at 100 photos a week, five site visits of twenty photos each, the free gigabyte is full in week 19. Most phones save 12 megapixels or more, so their files are bigger and that week comes sooner. Vercel doesn't bill a free account for going over. It shuts Blob off for 30 days, which makes that the week the app needs a paid plan.

So before shipping, I measured what each kind of compression keeps, and what it costs to keep it.

Two ways to make a file smaller

Every image format does one of two things, or both.

Lossless compression finds patterns and writes them down more briefly. Neighbouring pixels tend to be alike, so the encoder guesses each pixel from the ones around it and stores only how wrong the guess was. Small errors take few bits. Decode the file and every pixel comes back exactly.

Lossy compression decides that part of the picture isn't worth keeping. It rewrites the image as layers of coarse and fine detail, then rounds off the fine detail the eye is least likely to miss. That rounding is the only step that loses anything, and it's the step the quality setting controls.

Lossless

  1. Guess pixels
  2. Keep errors
  3. Pack the bits

Lossy

  1. Split detail
  2. Round it off
  3. Pack the bits
Both pipelines finish the same way. Lossy adds one step, and that step is where the savings come from.

Visually lossless is lossy compression tuned until nobody can see the rounding. It isn't a format or a setting. It's a claim about people, and it has a test: show viewers the original and the compressed image in the same place, swapping between them, and count how often they spot the difference. ISO/IEC 29170-2 standardises that procedure. SSIMULACRA 2, the quality score used below, calls 90 visually lossless and defines it the same way: "not noticeable by an average observer in a flicker test at 1:1 from a normal viewing distance." At 80 you can't tell them apart side by side. At 70 you can just about tell, if you look.

A lossless photo stays big

Lossless can only remove what is predictable, and a photo isn't very predictable. Every pixel carries a little sensor noise, and noise is random by definition. A lossless encoder has to store all of it. Claude Shannon put a floor under this in 1948: no lossless code can average fewer bits than the information actually in the source.

In practice that floor sits high. In David Barina's comparison of lossless formats, the two best, FLIF and JPEG XL, kept photos at about 9.4 bits per pixel. Raw is 24. So a lossless photo is still around 40% of its raw size.

One photo, KB

Raw pixels
10,288 KB

  • JPEG XL lossless
    2,395 KB
  • Original file
    547 KB
  • In the app
    232 KB
The same photo four ways, drawn to scale by area. The last box is 1600 px wide at JPEG quality 75.

The original had already made its call. 3.4 million pixels are 10 MB raw, and its JPEG keeps them in 547 KB, because JPEG is lossy. Ask for the same pixels losslessly and the best you get is 2.4 MB.

The trap is converting a JPEG to PNG "to keep the quality". The quality is already gone. The PNG keeps every pixel the JPEG decoder produced, rounding artefacts included, and pays for each one as if it were detail: 547 KB became 4.4 MB, 8.0 times bigger. If a file is already a JPEG and you want it smaller without losing a bit, JPEG XL can repack the JPEG's own data more tightly and hand back the original file byte for byte. That took this one to 456 KB, 17% smaller.

Which lossless format is smallest

Each format below ran at its slowest, strongest setting, and every file was checked to decode back to exactly the same pixels.

The photo, 2268 × 1512

PNG4.37 MBWebP3.08 MBAVIF3.76 MBJPEG XL2.39 MB

A screenshot of a post, 2560 × 1600

PNG89 KBWebP29 KBAVIF133 KBJPEG XL31 KB
Lossless file sizes, each encoder at its slowest setting. The photo is the original at full size. The screenshot is the top of a post on this site at 2× density.

On the photo, JPEG XL was smallest and PNG biggest. The screenshot nearly flipped the order at the top: WebP 29 KB, JPEG XL 31 KB, close enough to call a draw. AVIF, at 133 KB, lost even to PNG.

On photos that matches Barina's results, measured with older encoders: JPEG XL second only to FLIF, whose developers stopped work on it in favour of JPEG XL, and AVIF at or near the bottom on photos, illustrations and scanned books. AVIF comes from a video codec built for lossy frames, and its lossless mode shows it.

The first screenshot I took had this site's paper grain switched on, a faint noise texture over the whole page. It made the lossless WebP 12 times bigger and the JPEG XL 72 times bigger, 2.3 MB. Noise doesn't have to come from a sensor to cost bytes. WebP suffered least because the grain is one small tile repeated across the page, and WebP's lossless mode is good at finding exact repeats.

The smallest format isn't automatically the one to ship. As of November 2026, JPEG XL decodes in Safari since version 17, Chrome since 155 and Firefox since 158, but not yet in Edge or Samsung Internet. WebP works everywhere current. For lossless on the web today, I'd serve WebP and add JPEG XL as an upgrade for the browsers that take it.

How much loss you can see

Lossless is the wrong tool for photos people will look at on a screen. Here is the original against what I'd store instead.

The same photo at 1600 pixels wide and JPEG quality 75.
The original photo.
Left, the original JPEG: 547 KB. Right, what the app stores: 1600 px wide at JPEG quality 75, 232 KB. Both are scaled to this column, the way anyone will see them, and saved losslessly here so each side is exactly what its file decodes to.

At the size anyone will view it, the two are the same picture. The difference only shows when you zoom in, so the figure below does: a 312 × 208 px crop at 2×, every pixel drawn as four. Pick a format and a quality and compare.

The same crop after JPEG at quality 75, decoded.
A crop of the resized photo, as it was before encoding.
Format
Size
232 KB
Score
81, very high
Vs original
2.4× smaller

JPEG quality 75: 232 KB, SSIMULACRA 2 score 81, very high.

SSIMULACRA 2 against file size, every step of every format

Every measured result
Format and settingSizeSSIMULACRA 2
JPEG quality 2080 KB38
JPEG quality 30107 KB55
JPEG quality 40130 KB64
JPEG quality 50151 KB70
JPEG quality 60174 KB74
JPEG quality 70210 KB79
JPEG quality 75232 KB81
JPEG quality 80268 KB83
JPEG quality 85316 KB86
JPEG quality 90399 KB89
JPEG quality 95566 KB91
WebP quality 2061 KB44
WebP quality 3073 KB52
WebP quality 4085 KB58
WebP quality 5097 KB63
WebP quality 60112 KB68
WebP quality 70125 KB70
WebP quality 75131 KB72
WebP quality 80164 KB77
WebP quality 85210 KB81
WebP quality 90289 KB85
WebP quality 95439 KB89
AVIF quality 2031 KB35
AVIF quality 3043 KB50
AVIF quality 4061 KB63
AVIF quality 5091 KB73
AVIF quality 60135 KB79
AVIF quality 70186 KB83
AVIF quality 75215 KB85
AVIF quality 80253 KB87
AVIF quality 85291 KB89
AVIF quality 90401 KB91
AVIF quality 95599 KB93
JPEG XL distance 860 KB54
JPEG XL distance 674 KB62
JPEG XL distance 4100 KB72
JPEG XL distance 3124 KB77
JPEG XL distance 2178 KB83
JPEG XL distance 1.5222 KB86
JPEG XL distance 1303 KB89
JPEG XL distance 0.75377 KB91
JPEG XL distance 0.5539 KB93
  1. 1

    The resize saves more than the quality setting. JPEG quality 75 at the full 2268 px is 467 KB, 1.2 times smaller than the original file. Resizing to 1600 px keeps 50% of the pixels and makes it 2.0 times smaller again.

  2. 2

    Newer formats reach the same score with fewer bytes. JPEG at quality 75 scores 81 in 232 KB. WebP gets there in about 210 KB, AVIF gets there in about 154 KB, JPEG XL gets there in about 159 KB.

  3. 3

    Near the top, every point costs more. Going from quality 75 to 95 makes the JPEG 2.4 times bigger and moves the score from 81 to 91.

How it was measured
Photo
2268 × 1512 JPEG, 547 KB. The flower from the JPEG XL test images, © the JPEG XL Project Authors, BSD-3-Clause
Resized
1600 × 1067, Lanczos, before every encode
Encoders
libjpeg-turbo 3.2.0, libwebp 1.6.0, libavif 1.4.2 with aom, libjxl 0.12.0
Settings
Defaults, except the quality knob
Score
SSIMULACRA 2 against the resized photo, whole image
Crop
312 × 208 px at 644, 429, shown at 2×. Each side is the decoder's output, saved losslessly
Scores are for the whole image, not the crop. Every encoder runs at its defaults apart from the quality setting.

Step the quality down and each format fails in its own way. JPEG cuts the picture into 8 × 8 pixel blocks, and at low settings the blocks show. WebP smears fine texture into flat patches. AVIF and JPEG XL smooth texture away but keep edges clean, which is why they hold their scores at sizes where JPEG falls apart.

The same number doesn't mean the same thing across formats. WebP at quality 75 is 131 KB and scores 72, against JPEG's 232 KB and 81. Compare formats by score, never by setting.

What I picked, and why

The app will resize each photo to 1600 px on the long edge and save it as JPEG at quality 75, on the phone, before it uploads. That's 232 KB a photo, 2.4 times smaller than the original, with a score no one will notice side by side.

AVIF would reach the same score in about 34% fewer bytes. I still picked JPEG. Every phone can encode it on the device before upload, the quote PDFs the office sends can embed it as it is, and every browser, gallery and messaging app opens it. The AVIF saving is real, but it's small next to the one already made, and it would cost every place a JPEG simply works.

The JPEG itself can still shrink without changing format. jpegli, Google's newer JPEG encoder, reached the same score in about 198 KB, 15% smaller, and any JPEG decoder opens the result. It needs a native library on the phone, so the app will start with the phone's own encoder.

Photos stored, GB

Original files: 0.055 GB a week, so the 1 GB limit lasts about 4 months. In the app: 0.023 GB a week, so the 1 GB limit lasts about 10 months.

100 photos a week against Vercel Blob's free 1 GB, the dashed line.

At 232 KB a photo, the same 100 photos a week fill the free gigabyte in week 44 instead of week 19.

When lossless is the right call

Photos are the case lossy compression was built for. Other images break its assumptions.

  • Screenshots, UI, text and diagrams. Hard edges and flat colour are exactly what lossless predicts well and lossy handles badly. Rounding off fine detail leaves a speckled halo around every hard edge. As a JPEG at quality 75, my screenshot was 86 KB, 2.9 times the lossless WebP, and it scored 87. Lossy PNG, the trick pngquant uses, cuts the image to 256 colours instead. That came to 40 KB with a score of 99, close to lossless, though lossless WebP was still smaller. On the photo the same trick came to 893 KB and scored 59, because a photo needs far more than 256 colours.
  • Anything you'll edit and save again. Each lossy save rounds again, on top of the last rounding. Keep the master lossless and export lossy copies from it.
  • Pixels that are measurements. Medical scans, scientific images, maps. When someone will read values off the image, every value has to survive.
The same crop as a JPEG at quality 75: faint ripples beside every letter.
A crop of the screenshot, saved losslessly: crisp text.
A 312 × 208 crop of the screenshot, every pixel drawn as four. Left is lossless: WebP stores the whole screenshot in 29 KB. Right is JPEG quality 75: 86 KB and a SSIMULACRA 2 score of 87.

Lossless promises every bit back. For a photo, most of those bits are noise the eye was never going to see, and storing them is the most expensive way to keep a picture nobody can tell apart from a far smaller one.