The idea: one person should not change what the world sees

A clinic wants to publish how many people in a survey have flu. It does not want anyone to learn whether one person, say Hoa, has flu. Take two tables: D with Hoa and D′ without. They are neighbouring databases: they differ in one person. If the published answer looks almost the same whichever table it came from, the answer cannot reveal Hoa. Differential privacy makes "almost the same" exact: for every possible answer x, the chance of x from D is at most eε times the chance from D′, and the same the other way round. This must hold for every pair of neighbours, so it protects every person, not only Hoa. All people and data on this page are made up.

Two tables, D with Hoa (count 4) and D prime without Hoa (count 3), each go through the same box: count plus Laplace noise of scale b equal to delta over epsilon. Out come two overlapping peaked curves centred on 4 and 3; at any answer x the ratio of their heights is at most e to the epsilon
The same noisy count run on two neighbouring tables gives two overlapping answer curves; their ratio is never more than eε.

Pick a database and ε, then press Query for one answer or Query ×20 to ask the same question 20 times. Randomized Response runs the local version. Or pick a demo and press Run Demo. The top left shows the table, the top right the curator's numbers and the two budgets, and the large panel the two answer curves with every released answer as a dot.

Neighbours and sensitivity

The query is COUNT(*) WHERE flu = 'yes'. On D the answer is 4 (Ana, Chi, Fay, Hoa); on D′ it is 3. Adding or removing one person changes any count by at most 1. That largest change over all neighbours is the sensitivity Δ of the query, so Δ = 1 here. A sum of salaries capped at 100 would have Δ = 100; a query with no bound on one person's effect has no finite Δ and cannot be answered this way.

The Laplace mechanism

The curator holds the data and never releases the true count. It adds noise drawn from the Laplace distribution with mean 0 and scale b = Δ / ε. Its density is a two-sided exponential: a sharp peak at 0 with sides that fall off exponentially.

  • p(noise = z) = e−|z| / b / (2b)
  • the average size of the noise, E|z|, is exactly b

In Demo 1, ε = 1 so b = 1. The draw is +0.35, and the curator releases 4 + 0.35 = 4.35 (Demo 1: one noisy count). The page draws the noise from a seeded generator, so each demo gives the same numbers every time. A real curator uses a secure random source. For densities in general see Continuous Distributions; the bell curve, used by the related Gaussian mechanism, is on the Normal Distribution page.

Why the ratio stays below eε

An answer x from D has density e−|x − 4| / b / (2b); from D′ it has e−|x − 3| / b / (2b). Their ratio is e(|x − 3| − |x − 4|) / b. The two distances differ by at most Δ = 1, so the ratio is at most e1/b = eε. That is the whole proof, and it is why b must be Δ / ε.

released xp(x | D) / p(x | D′) at ε = 1example
x ≥ 4eε = 2.72 (the largest)Demo 1: x = 4.35, densities 0.351 and 0.129
3 < x < 4e(2x − 7) / b, between the twoDemo 6: x = 3.58 gives 1.18
x ≤ 3e−ε = 0.37 (the smallest)Demo 2: x = 2.58 from D′, densities 0.121 and 0.330

So whatever an observer sees, it can make them at most 2.72 times more (or less) confident that Hoa is in the data than they were before (Demo 2: neighbour D′). The bound holds even if the observer knows everyone else's row.

Choosing ε: privacy against accuracy

ε is the privacy loss. Smaller ε means wider noise: the two curves almost cover each other, and the answer is less useful. Larger ε means sharper noise and a more accurate answer, but the curves pull apart.

εb = Δ / εaverage errorratio bound eεon the page
0.110101.11Demo 3: D gives 7.53, D′ gives −1.17
0.5221.65
1112.72Demos 1, 2: 4.35 and 2.58
20.50.57.39Demo 4: 4.18 and 2.79
Three small charts side by side, each with a blue curve centred at 4 for D and an orange curve centred at 3 for D prime. At epsilon 0.1 the curves are wide and almost the same, ratio at most 1.11. At epsilon 1 they overlap a lot, ratio at most 2.72. At epsilon 2 they are sharp and clearly apart, ratio at most 7.39
Small ε hides the person but blurs the answer; large ε gives a sharp answer and a weaker promise.

The canvas always draws the taller curve the same height, so only the width changes; the note in the panel gives the true peak height 1 / (2b).

Composition and the privacy budget

Each answer uses fresh noise, so asking again and averaging removes the noise. The average of n answers has a typical error of about √2·b / √n (the law of large numbers at work). This is why privacy losses add up: k answers at ε each are together k·ε-differentially private (sequential composition). A curator therefore keeps a privacy budget per database and refuses queries once it is spent.

  • Demo 5: 20 answers at ε = 0.1. Total cost 20 × 0.1 = 2. The mean is 5.68 (true 4); its typical error is √2·10 / √20 = 3.16. One answer at ε = 2 costs the same and has b = 0.5 (Demo 4 got 4.18). Splitting a budget into many small queries wastes it.
  • Demo 6: the budget runs out. With a cap of 3 and ε = 1, the curator answers 4.35, 3.58 and 3.79, then refuses the fourth query: 3.0 of 3.0 is spent.
  • Demo 7: no cap. 20 answers on D average 4.17 and 20 answers on D′ average 2.92, each with a typical error of 0.32. The gap of about 1 shows that the extra person has flu. Each table has spent ε = 20, and a bound of e20 promises nothing. The budget is the defence.

Randomized response: local privacy

Sometimes nobody should hold the true data, not even a curator. In randomized response each person adds the noise before answering. They flip a coin: heads, they tell the truth; tails, they flip again and say yes on heads, no on tails. Then P(says yes | flu) = 3/4 and P(says yes | no flu) = 1/4. The ratio is 3, so each answer is ε = ln 3 ≈ 1.10 differentially private. This is local differential privacy.

A coin tree. Coin 1 heads with probability one half: tell the truth. Coin 1 tails: coin 2, heads says yes, tails says no, each one quarter. A person with flu says yes with probability 3/4; a person without flu says yes with probability 1/4; the ratio 3 gives epsilon equal to ln 3
Two coins give every answer a deniable story, and the known odds still let the analyst estimate the rate.

The analyst knows the odds. Expected yes answers = n/4 + (flu count)/2, so the estimate is 2·(said yes) − n/2. In Demo 8, Hoa has flu but the coins made the answer "no"; Dan and Ivo have no flu but said "yes". Five of 10 said yes, so the estimate is 2·5 − 5 = 5 (true 4). With 1000 made-up people, 400 with flu, 440 said yes and the estimate is 2·440 − 500 = 380 (Demo 8: randomized response). Local noise is much larger than central noise for the same ε, so it needs many people.

central (Laplace curator)local (randomized response)
who sees true datathe trusted curatornobody but each person
noise addedonce, to the answerto every person's answer
error of a count of n peopleabout b, whatever n isgrows like √n
main riska breached or careless curatortoo few people for a useful estimate

What differential privacy does and does not protect

It limits what released statistics reveal about any one person, including attacks that link the output with other data. It does not hide facts about the whole group: "4 in 10 have flu" is meant to be learned. It does nothing for the raw table itself, which still needs access control and encryption. Unlike k-anonymity, which changes the rows that are published, it adds randomness to answers and gives a guarantee that does not depend on what the attacker already knows.

See also K-Anonymity and l-Diversity, which protects a published table by generalizing and suppressing quasi-identifiers instead of adding noise.

What the page leaves out

(ε, δ)-differential privacy and the Gaussian mechanism; advanced and parallel composition, Rényi and zero-concentrated DP accounting; the exponential mechanism for non-numeric answers; sensitivity of sums, means and histograms and the clipping they need; rounding and clamping of the released count, and floating-point attacks on naive Laplace sampling (real libraries use discrete or snapping mechanisms); privacy-preserving machine learning (DP-SGD); and how organisations choose ε in practice.

On the mind map

Open the Web & Security mind mapWeb & SecurityCrypto building blocks: keys, hashes, signaturesCrypto building blocksStoring passwords: slow salted hash, never plaintextStoring passwordsBrowser rules: which request carries whatBrowser rulesRequest attacks: trick a browser or a serverRequest attacksLogin & identity: prove who you areLogin & identityOWASP Top 10 2025: common flaws, then the fixOWASP Top 10 2025OWASP: supply chain & ops: dependencies, logs and error pathsOWASP: supply chain & opsBroken access controlBroken access controlcheck ownership and role on the serverK-anonymityK-anonymityEvery zip/age/sex combo in at least k rowsDifferential privacynoise b = Δ/ε, ratio ≤ e^ε, budget adds upSecurity misconfigurationSecurity misconfigurationdefaults, debug errors, missing headersCryptographic failuresCryptographic failuresno TLS, MD5, ECB mode, hard-coded keysInsecure designInsecure designtrusting the client, races, no try limitsSTRIDE threat modelSTRIDE threat modelSix threats per DFD element, each mitigatedAuthentication failuresAuthentication failuresstuffing, brute force: rate limit, MFAIntegrity failuresIntegrity failuresverify data and code: HMAC, SRI, fixed algOpen the Web & Security mind mapWeb & Securitycommon flaws, then the fixOWASP Top 10 2025Broken access controlBroken access controlcheck ownership and role on the serverK-anonymityK-anonymityEvery zip/age/sex combo in at least k rowsDifferential privacynoise b = Δ/ε, ratio ≤ e^ε, budget adds upSecurity misconfigurationSecurity misconfigurationdefaults, debug errors, missing headersCryptographic failuresCryptographic failuresno TLS, MD5, ECB mode, hard-coded keysInsecure designInsecure designtrusting the client, races, no try limitsSTRIDE threat modelSTRIDE threat modelSix threats per DFD element, each mitigatedAuthentication failuresAuthentication failuresstuffing, brute force: rate limit, MFAIntegrity failuresIntegrity failuresverify data and code: HMAC, SRI, fixed alg
This page on the Web & Security mind map · 42 pages in 7 branches · open it to see the whole map and test yourself in recall mode.