The math

How AI image detection actually works, with the real numbers.

Detector scores feel like a verdict. Underneath, they're the output of a probability model, a frequency-domain comparison, or a compression-history diff — each with well-defined math and well-defined blind spots. This page walks through the actual formulas, using the same techniques this site's own local checker runs.

Classifier confidence

A detector score is a sigmoid output, not a truth value.

Most AI-image classifiers are trained as binary classifiers: real (label 0) vs. AI-generated (label 1). The network outputs a raw score (a logit) that gets squashed into a 0–1 range with a sigmoid function, p = 1 / (1 + e^-x), and training minimizes binary cross-entropy loss, L = -(y·log(p) + (1-y)·log(1-p)), across millions of labeled examples. The output p is literally "how far this image sits from the model's learned decision boundary," projected onto a probability-shaped curve. It is not measuring authorship, intent, or ground truth — it's measuring resemblance to the two clusters the model saw during training.

Threshold

Where the cutoff lives

Most tools report "AI-generated" once p crosses 0.5, but that threshold is a design choice, not a law of nature. Lowering it catches more AI images (higher recall) at the cost of flagging more real ones (lower precision). Every detector is tuned somewhere on that trade-off curve, and vendors rarely publish where.

ROC / AUC

How "accuracy" is usually measured

Benchmark claims like "94% accuracy" typically come from a ROC curve — plotting true-positive rate against false-positive rate across every possible threshold — condensed into one AUC (area under curve) number. A high AUC on a benchmark set says nothing about performance on generators or edits that weren't in that benchmark.

Distribution shift

Why new models break old detectors

A classifier trained on 2023-era Midjourney and Stable Diffusion output learns the statistical fingerprint of those generators. A 2025 model with a different architecture, decoder or training set can sit outside the learned boundary entirely — detection accuracy on unseen generators routinely drops well below in-sample benchmark numbers.

Base-rate math

The single most important number detector marketing never mentions.

Sensitivity and specificity are properties of the detector. But the number you actually care about — "given a positive result, what's the chance this image really is AI?" — also depends on how common AI images are in whatever pile you're checking. That's Bayes' theorem, and the difference it makes is not subtle.

ScenarioBase rate of AI imagesDetector: 95% sensitivity, 90% specificityP(actually AI | flagged positive)
Random photo from a general social feed2%Same detector, same thresholds16.2% — most positives are false alarms
Images already pulled into a "suspected AI" moderation queue50%Same detector, same thresholds90.5% — most positives are correct

Worked calculation

Row 1, in full.

P(positive) = P(AI)·sensitivity + P(real)·(1 − specificity) = 0.02 × 0.95 + 0.98 × 0.10 = 0.019 + 0.098 = 0.117. P(AI | positive) = 0.019 ÷ 0.117 = 0.162. The exact same math, run on a pre-filtered queue where half the images are already suspected AI (P(AI)=0.5), gives P(positive) = 0.475 + 0.05 = 0.525, and P(AI | positive) = 0.475 ÷ 0.525 = 0.905. Same detector. Same accuracy claims. A 5.6× difference in how much you should trust a positive result, purely from context.

Frequency-domain analysis

Why some detectors look at the image sideways.

Pixels aren't the only representation worth analyzing. Converting an image into frequency space — via a 2D Fourier or discrete cosine transform — turns "how detailed is this area" questions into "how much energy exists at each spatial frequency" questions, and generative models leave traces there that are invisible to the eye.

Upsampling

Checkerboard artifacts

Many image generators use transposed convolution or nearest-neighbor-plus-convolution layers to upscale a small latent grid into a full image. This is a well-documented source of regular, grid-aligned periodicity — informally called "checkerboard artifacts" — that shows up as sharp, unnatural peaks when you take a radially-averaged power spectrum of the image.

Natural falloff

What a real camera photo looks like spectrally

Ordinary photographs tend to follow a roughly 1/f² power-law falloff in their frequency spectrum — a well-known property of natural images sometimes called "pink noise" structure. A spectrum with sharp, narrow peaks instead of a smooth falloff is a signal worth investigating, though compression and resizing can also distort it.

Diffusion vs GAN

Not all generators leave the same fingerprint

GAN-era upsampling artifacts are comparatively well studied and easier to detect spectrally. Diffusion models denoise iteratively through a different architecture and tend to leave a subtler signature, though latent-diffusion pipelines (Stable Diffusion included) still decode through a convolutional VAE decoder that can reintroduce similar high-frequency regularities.

This site's own technique

Error-level analysis: the exact formula the local checker runs.

JPEG compression divides an image into 8×8 pixel blocks, transforms each with a discrete cosine transform, and quantizes the result — rounding high-frequency coefficients more aggressively than low-frequency ones, according to a quality-dependent divisor table. That rounding is lossy, and it stabilizes: resaving an already-compressed region at the same quality changes it only slightly, because it's already sitting near that quantization grid. A freshly generated, pasted, or never-before-compressed region shifts much more, because it isn't.

1

Recompress

The checker draws your image to canvas, then re-encodes it via canvas.toDataURL('image/jpeg', 0.9) — a second lossy JPEG pass at a fixed quality.

2

Diff every pixel

It loads the recompressed version back in, draws both to canvas, and computes |R−R'| + |G−G'| + |B−B'| per pixel between the original and the resave.

3

Amplify

The raw difference is usually tiny (single digits per channel), so the checker multiplies it by a fixed gain — amp = min(255, diff × 8) in this site's code — so it's visible as a heatmap instead of a wash of near-black pixels.

4

Read it as variance, not a verdict

A uniform, low-error result means the whole image was compressed once, consistently — true of both an untouched photo and a single-pass AI generation. A patchy result, with one region lighting up far brighter than the rest, means that region has a different compression history than its surroundings — the classic signature of a local edit or a pasted-in element, independent of whether the base image is AI or real.

Reading a result

Precision, recall, and the confusion matrix behind "accuracy."

A worked example: a benchmark of 1,000 images (250 actually AI-generated, 750 actually real camera photos), run through a detector with 90% sensitivity and 90% specificity.

OutcomeCountMeaning
True positive225Actually AI, correctly flagged
False negative25Actually AI, missed
False positive75Actually real, wrongly flagged
True negative675Actually real, correctly cleared

The arithmetic

What those four numbers mean in practice.

Precision = 225 ÷ (225+75) = 75%. Recall = 225 ÷ (225+25) = 90%. F1 = 2 × 0.75 × 0.9 ÷ 1.65 = 81.8%. Overall accuracy = (225+675) ÷ 1000 = 90% — the headline number vendors quote, and the one that hides the fact that 1 in 4 positive flags in this benchmark is wrong.

What the math can't tell you

None of this replaces provenance.

Every technique above — classifier confidence, frequency analysis, error-level analysis, embedded metadata — produces a statistical signal about the file you have in hand. None of them can tell you who made an image, whether it was disclosed, or whether it's being used honestly. For that, use the verification workflow and combine it with the local checker, which reports its evidence directly instead of collapsing it into one score.

FAQ

Common questions about detector math.

Is a detector confidence score the same as a probability the image is AI-generated?

No. It's the model's estimated probability that the image resembles its synthetic training examples more than its real ones — a different quantity from the true probability, which also depends on the base rate of AI images in whatever you're checking.

Why can a 90%-accurate detector still be wrong most of the time?

Base rates. If only 2% of the images you check are actually AI-generated, a 95%-sensitivity, 90%-specificity detector will still be wrong on the majority of images it flags positive, because the much larger real-image pool produces more false positives in absolute terms than the small AI pool produces true positives.

What does error-level analysis actually measure?

It resaves an image at a fixed JPEG quality and measures the pixel difference from the original. Regions already compressed near that quality change little; freshly edited or pasted regions change more. It flags inconsistent compression history, not AI generation specifically.

Does a smooth frequency spectrum prove an image is real?

No. It's one signal among several. Post-processing, resizing and re-compression can smooth out generator artifacts, and some generators leave a much weaker spectral signature than others.