JPEG generation loss is the quality an image loses each time it is decoded and re-encoded with a lossy codec. It matters whenever a file gets edited, forwarded and saved again — a flyer that went through email, WhatsApp and a screenshot before it reached you. The folklore says every save makes it worse. I measured it on text, which is the content JPEG damages first, and the folklore is mostly wrong: at a fixed quality setting the loss converges after the first save, and the quality number does far more damage than the number of saves.

The whole measurement is about 40 lines of Node with sharp. You can run it in under a minute and change any assumption I made.

Disclosure on process: this post was drafted with AI assistance from the project's code and the script below; the numbers are the output of running that script on 2026-09-22.

Why measure letters rather than the whole image

Letterforms are almost entirely high-contrast edges, and high-contrast edges are exactly where JPEG's discrete cosine transform discards information. A whole-image average hides this: most pixels in a poster or a screenshot are flat background that compresses almost losslessly, so the mean error looks tiny while the text visibly grows a halo.

So the script measures twice — once over every pixel, and once over only the pixels that sit on a letter outline. The outline mask is found with a simple gradient on the lossless original: any pixel whose horizontal plus vertical intensity difference exceeds 40 (on a 0–255 scale) counts as an edge. On the test image that is 20,826 pixels, 3.5% of the frame.

Environment

  • Node.js v24.19.0
  • sharp 0.34.5 (bundles libjpeg-turbo; default JPEG options, so 4:2:0 chroma subsampling below quality 90)
  • macOS, run on 2026-09-22

Anything newer should produce the same shape of result; the absolute numbers will shift a little with the encoder.

The test image

There is no photograph involved, on purpose. The source is an SVG rendered to a lossless PNG, so the ground truth is exact and nobody can argue the "original" was already compressed:

  • a heavy 86px display headline
  • a 30px serif line
  • a 15px hairline serif — the hard case, thin strokes with little contrast to spare
  • a 120px price in colour

1200×500, flat off-white background, 40.1 KB as PNG.

The script

Save this as jpeg-loss.mjs in a project that has sharp installed and run node jpeg-loss.mjs.

import sharp from "sharp"; const W = 1200, H = 500; const svg = `<svg width="${W}" height="${H}" xmlns="http://www.w3.org/2000/svg"> <rect width="${W}" height="${H}" fill="#f2efe9"/> <text x="60" y="140" font-family="Helvetica, Arial" font-size="86" font-weight="700" fill="#141414">GRAND OPENING</text> <text x="60" y="240" font-family="Georgia, serif" font-size="30" fill="#222">Issued 2019 · thin serif at 30px</text> <text x="60" y="300" font-family="Georgia, serif" font-size="15" fill="#333">Issued 2019 · hairline serif at 15px</text> <text x="60" y="400" font-family="Helvetica, Arial" font-size="120" font-weight="800" fill="#b8321e">$4.50</text> </svg>`; // Lossless ground truth. const base = await sharp(Buffer.from(svg)).png().toBuffer(); const baseRaw = await sharp(base).greyscale().raw().toBuffer(); // Edge mask: pixels on a letter outline, found by gradient on the original. const mask = new Uint8Array(W * H); let edgeCount = 0; for (let y = 1; y < H - 1; y++) { for (let x = 1; x < W - 1; x++) { const i = y * W + x; const gx = baseRaw[i - 1] - baseRaw[i + 1]; const gy = baseRaw[i - W] - baseRaw[i + W]; if (Math.abs(gx) + Math.abs(gy) > 40) { mask[i] = 1; edgeCount++; } } } // Mean absolute error vs the original, whole image and edges only. async function mae(buf) { const raw = await sharp(buf).greyscale().raw().toBuffer(); let all = 0, edge = 0; for (let i = 0; i < raw.length; i++) { const d = Math.abs(raw[i] - baseRaw[i]); all += d; if (mask[i]) edge += d; } return { all: all / raw.length, edge: edge / edgeCount }; } for (const quality of [92, 75]) { let cur = base; for (let round = 1; round <= 10; round++) { cur = await sharp(cur).jpeg({ quality }).toBuffer(); // encode const m = await mae(cur); if ([1, 3, 10].includes(round)) { console.log(`q${quality} save ${round}: ${(cur.length / 1024).toFixed(1)} KB` + ` whole=${m.all.toFixed(2)} edges=${m.edge.toFixed(2)} ratio=${(m.edge / m.all).toFixed(1)}x`); } cur = await sharp(cur).png().toBuffer(); // decode, as an editor would } } 

The decode step at the end of each round is the part people forget. A real "open, save, open, save" loop always decodes to pixels in between; feeding the JPEG bytes straight back into the encoder measures something different.

Results

Mean absolute error against the lossless original, greyscale, 0–255 scale. Lower is better.

Quality Saves File Whole image Letter edges Edges ÷ whole
92 1 39.7 KB 0.21 2.28 10.9×
92 3 39.7 KB 0.23 2.64 11.5×
92 10 39.6 KB 0.29 3.18 11.0×
75 1 27.0 KB 0.49 5.53 11.3×
75 3 27.0 KB 0.50 5.70 11.4×
75 10 27.0 KB 0.51 5.81 11.4×

Three things the numbers say

Letter edges absorb about eleven times the average error, at every quality and every round. They are 3.5% of the pixels and they carry most of the damage. This is the mechanical reason text is the hardest thing to edit in a JPEG: the codec is, in effect, tuned to throw away the information letters are made of.

Re-saving the same image does not spiral. At quality 75, going from one save to ten added about 5% to the edge error — the first save accounts for roughly 95% of where you end up. At quality 92, ten rounds added about 39%, still nowhere near "ten times worse". JPEG quantisation converges toward a fixed point when the pixels are not changing between saves, so the second and third save land mostly on the same grid the first one already snapped to.

The quality setting is the lever that matters. One save at quality 75 did 2.4× the edge damage of one save at quality 92, and bought 12.7 KB. On an image whose whole purpose is legible words, that is rarely a trade worth making.

What I could not reproduce

The compounding people remember is usually blamed on the 8×8 block grid landing on different pixels after a crop or resize between saves. I tried to measure that twice and could not.

The first attempt was a measurement artefact: cropping 3 px and resizing back shifted the whole image, so the error against the original was misalignment, not compression — the numbers jumped to 90 and meant nothing. The second attempt shifted the content by 3 px before each save and shifted it back before comparing, so the grid phase differed from the original's; the curve was indistinguishable from the unshifted one. That is one experiment, not a proof, so I am not claiming the effect does not exist — only that this script does not show it. If you can make it appear, I want to see the setup.

Mistakes that make this measurement lie

Measuring only whole-image error. It is dominated by flat background and will tell you the JPEG is nearly perfect while the text is visibly haloed. Always add an edge or region-of-interest metric.

Starting from a JPEG. If your "original" was already lossy, save one is really save N+1 and everything converges immediately — you will conclude re-saving does nothing at all. Render the ground truth losslessly.

Skipping the decode between rounds. Re-encoding JPEG bytes without decoding does not model what an image editor does.

Comparing across resolutions. Any resize between rounds resamples every pixel; the error you measure is the resampling, not the codec.

When this does not apply

The image here is synthetic — flat background, clean vector type. Photographs behave differently in the whole-image column (grain and gradients absorb error), though the edge column is the same phenomenon.

This is one encoder at default settings. mozjpeg, 4:4:4 chroma subsampling, or progressive encoding will move the absolute numbers. I would expect the three conclusions to survive, but that is expectation, not measurement.

Mean absolute error is a blunt instrument. It does not capture ringing patterns or perceptual weighting. It was chosen because it is trivially reproducible and needs no dependency beyond sharp.

Where this came from

Disclosure up front: EditTextImage is the product I work on. EditTextImage replaces text that is already rendered into a finished image — a poster, a screenshot, a product photo — while keeping the original typeface and background. JPEG edge damage is the thing that limits how well any tool can sample and rebuild letters, which is why it got measured. The longer write-up, including a comparison of four ways to edit text in a JPEG and when each one is the wrong choice, is the canonical version of this post: how to edit text in a JPEG image online.

FAQ

Should I convert a JPEG to PNG before editing it?
Converting recovers nothing. The detail JPEG discarded is gone, and a PNG made from a JPEG preserves the damage losslessly. What conversion does buy you is a lossless working copy, so the edits you make from then on cost no further quality. Do that, edit, and export to JPEG once at the end — at a high quality number, because the table above says that number, not the count of saves, is what costs you.

What quality should I export at?
Ninety or above if the tool lets you choose, and PNG if the image will be edited again. In the measurement, quality 92 produced an edge error of 2.28 against 5.53 at quality 75 on the identical image, for a 12.7 KB difference in file size. For a photograph without text, quality 75–85 is often fine; for anything whose point is readable words, the saving is not worth it.

Does cropping or resizing between saves make it worse?
Resizing between saves definitely adds error, but that error is resampling, not compression, and it would happen with a lossless format too. The specific claim that a crop shifts the 8×8 grid and compounds JPEG loss is the one I could not reproduce with this script; treat it as unverified rather than false.

If you run this with mozjpeg or with chromaSubsampling: "4:4:4", I would genuinely like to know whether the 11× ratio holds — post your numbers in the comments.