Home / Journal / Technical research
What double JPEG compression leaves behind, and what it does not prove
Saving a JPEG twice empties 41% of DCT histogram bins on average in my test, versus 0.1% for a single save. A measurable trace, but not proof of manipulation.

In SMART ONE I work with images whose history matters, so I wanted to see one of the oldest forensic clues with my own eyes. When a JPEG photo is opened, edited and saved again, the second compression leaves a statistical trace that you cannot see but can measure. Image forensics has used this trace for twenty years. I reproduced the basic effect on five public-domain images. Here is what I found, and, just as important, what it does not prove.
Why a second save leaves a mark
JPEG cuts the image into 8 × 8 blocks, transforms each block with the discrete cosine transform (DCT) and divides every coefficient by a quantisation step before rounding. If the image is saved again with a different quality, the coefficients are quantised twice with two different steps. Popescu and Farid (2004) showed that this double quantisation produces periodic peaks and empty bins in the histogram of DCT coefficients, an artefact that a single compression does not create. Later work refined the idea into detectors that can also localise the recompressed region (Bianchi & Piva, 2012). Farid (2009) used a related effect, “JPEG ghosts”, to find composites built from images of different quality.
The experiment
- Images: five public-domain test images (coffee, chelsea, rocket, Hubble deep field, immunohistochemistry), greyscale.
- Single: saved once at JPEG quality 90.
- Double: saved at quality 60, decoded, then saved again at quality 90.
- Measure: for nine low-frequency DCT positions, divide the decoded coefficients by the final quantisation step, round, and count how many histogram bins between −15 and +15 (zero excluded) are empty.
Results
| Image | Empty bins, saved once | Empty bins, saved twice |
|---|---|---|
| coffee | 0.0% | 39.6% |
| chelsea | 0.0% | 58.5% |
| rocket | 0.4% | 24.8% |
| Hubble deep field | 0.0% | 20.7% |
| immunohistochemistry | 0.0% | 60.4% |
| Mean | 0.1% | 40.8% |
The histogram of a single-compressed image is smooth. After double compression, whole bins disappear in a regular pattern, because the coarse first step (quality 60) only allowed certain values, and the fine second step cannot recreate the values in between. The cover figure shows this for one coefficient: every fifth bin survives.
What this does not prove
This is where many popular “fake detectors” go wrong, and it is the line I hold in my own project.
- Double compression is not manipulation. Messengers, social networks and photo apps recompress images all the time. A photo sent through two apps is double-compressed and perfectly genuine.
- The effect depends on the settings. It is strong when the second quality is higher than the first, as in my test. It weakens or disappears in other cases, after resizing, or when the 8 × 8 grid is shifted by cropping.
- Absence is not proof either. A careful editor can avoid the trace, and many edits happen before the first compression.
So the honest statement is narrow: this file shows statistical signs of having been JPEG-compressed at least twice, with these settings. It is evidence about the file’s history, not a verdict about whether the content is true.
What this means for my work
SMART ONE includes indicators of this kind: compression steps and pixel-grid regularities, next to camera-noise analysis in the tradition of Lukáš, Fridrich and Goljan (2006). SMART ONE is not a validated manipulation detector, and its reports say so. Each indicator is presented as a measured property with its known causes, innocent ones included. The experiment above is the simplest version of what those indicators measure. Publishing it with code is my way of showing exactly how much one such number can and cannot carry.
If you are just starting
- Every JPEG save throws away detail. Keep masters in PNG, TIFF or EXR and export JPEG last.
- A measurable trace in a file is a fact about the file’s history, not a verdict about truth.
- Before you trust an image-analysis tool, ask about its error rate and its innocent explanations.
Reproduce it
A shortened version that checks one coefficient (1,1); the full script averages nine positions and five images.
import io, numpy as np
from PIL import Image
from scipy.fft import dctn
from skimage import data, color
a = (color.rgb2gray(data.coffee())*255).round().astype(np.uint8)
def save(x, q):
b = io.BytesIO(); Image.fromarray(x).save(b, 'JPEG', quality=q); b.seek(0); im = Image.open(b); im.load(); return im
def empty_share(im):
x = np.asarray(im, float) - 128; h, w = (x.shape[0]//8)*8, (x.shape[1]//8)*8
C = dctn(x[:h, :w].reshape(h//8, 8, w//8, 8).transpose(0, 2, 1, 3), axes=(2, 3), norm='ortho')
Q = np.array(list(im.quantization[0])).reshape(8, 8) # natural order in Pillow 12
k = np.round(C[:, :, 1, 1]/Q[1, 1]).astype(int).ravel()
return np.mean([(k == i).sum() == 0 for i in range(-15, 16) if i])
print(empty_share(save(a, 90)), empty_share(save(np.asarray(save(a, 60)), 90)))
References
- Bianchi, T., & Piva, A. (2012). Image forgery localization via block-grained analysis of JPEG artifacts. IEEE Transactions on Information Forensics and Security, 7(3), 1003–1017.
- Farid, H. (2009). Exposing digital forgeries from JPEG ghosts. IEEE Transactions on Information Forensics and Security, 4(1), 154–160.
- Lukáš, J., Fridrich, J., & Goljan, M. (2006). Digital camera identification from sensor pattern noise. IEEE Transactions on Information Forensics and Security, 1(2), 205–214.
- Popescu, A. C., & Farid, H. (2004). Statistical tools for digital forensics. In Information Hiding (LNCS 3200, pp. 128–147). Springer.
SEMEN KLENOV · Research notes on visual data. Drafted with AI assistance; experiment code and numbers checked by the author.