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.
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 x | p(x | D) / p(x | D′) at ε = 1 | example |
|---|---|---|
| x ≥ 4 | eε = 2.72 (the largest) | Demo 1: x = 4.35, densities 0.351 and 0.129 |
| 3 < x < 4 | e(2x − 7) / b, between the two | Demo 6: x = 3.58 gives 1.18 |
| x ≤ 3 | e−ε = 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 error | ratio bound eε | on the page |
|---|---|---|---|---|
| 0.1 | 10 | 10 | 1.11 | Demo 3: D gives 7.53, D′ gives −1.17 |
| 0.5 | 2 | 2 | 1.65 | |
| 1 | 1 | 1 | 2.72 | Demos 1, 2: 4.35 and 2.58 |
| 2 | 0.5 | 0.5 | 7.39 | Demo 4: 4.18 and 2.79 |
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.
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 data | the trusted curator | nobody but each person |
| noise added | once, to the answer | to every person's answer |
| error of a count of n people | about b, whatever n is | grows like √n |
| main risk | a breached or careless curator | too 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.