Search

Search papers and lessons

Differential Privacy

Level 4 · 10 min read

Differential privacy limits how much any one person's data can change what a released answer looks like, by adding carefully scaled random noise to the answer.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • Calculus
  • Linear algebra
  • Algorithms
  • Security & cryptography
  • ReadReady to readNot yet

TL;DR

Differential privacy is a promise about a randomised release of information. If someone's record is added to or removed from a dataset, the chance of any particular output changes by at most a fixed factor, controlled by a number called epsilon. The mechanism that makes this true adds random noise to the answer, scaled to how much one record can move that answer.

Builds on: Randomized Algorithms, Laplace Distribution, Global Sensitivity · Leads to: Gaussian Mechanism, Differentially Private SGD

Where it's used

Training neural networks on private data. Abadi and colleagues showed how to train a deep network with stochastic gradient descent while limiting what the trained weights reveal about any one training example. Their method, DP-SGD, clips each example's gradient and adds noise to the sum, as described in their paper.

A hospital counting patients. Imagine a hospital that wants to publish how many patients in a year had a certain condition, without making it possible to tell from the published number whether a specific person was among them. This is a scenario used to explain the idea, not a reported deployment.

How it works

We use a tiny dataset. Five people each have a yes or no answer to one question, and the query is the number of yeses. In this dataset the true answer is 3. We want to release a noisy version of the answer with a privacy level epsilon equal to 1.

flowchart LR
  D[Dataset D with 5 rows] --> Q[Query: count of yeses = 3]
  Q --> S[Sensitivity: largest change from one row]
  S --> B[Noise scale b = sensitivity / epsilon]
  B --> R[Release 3 plus Laplace noise]
  1. Start with the true answer. The dataset D has five rows and the count of yeses is 3. Check: the released number should be near 3, but not exactly 3.
  2. Find the sensitivity. Look at every neighbouring dataset, one with a row added or removed. Removing one row gives a count of 2 or 3. Adding one gives 3 or 4. The largest change is 1, so the sensitivity is 1. Check: no single row can move the count by 2.
  3. Pick the noise scale. Use scale b=sensitivity/ε=1/1=1b = \text{sensitivity} / \varepsilon = 1 / 1 = 1. Check: a smaller epsilon would give a bigger scale, so more noise.
  4. Draw the noise. Draw one number from a Laplace distribution with centre 0 and scale 1. Suppose the draw is 0.6. Check: the noise can be positive or negative.
  5. Release the noisy answer. Publish 3 + 0.6 = 3.6. Check: an analyst sees 3.6 and cannot tell the true count is 3.
  6. Compare with the neighbour. Suppose the dataset D' has one extra yes, so its true count is 4. The chance of releasing 3.6 from D is set by a Laplace density centred at 3. From D' it is set by a density centred at 4. The density from D divided by the density from D' at 3.6 is e−0.2≈0.82e^{-0.2} \approx 0.82, and the reverse ratio is e0.2≈1.22e^{0.2} \approx 1.22. Check: both ratios lie between e−1≈0.37e^{-1} \approx 0.37 and e1≈2.72e^{1} \approx 2.72, so the two datasets give nearly the same output chances.
  7. Read the guarantee. Because the ratio is bounded for every output and every neighbour, one person's row changes what an outside observer can infer by at most a factor eεe^{\varepsilon}.

The math

Definition: Epsilon-differential privacy

A randomised mechanism M\mathcal{M} is ε\varepsilon-differentially private if, for every pair of neighbouring datasets DD and D′D' and every set of outputs SS,

P[M(D)∈S]≤eε P[M(D′)∈S].P[\mathcal{M}(D) \in S] \le e^{\varepsilon} \, P[\mathcal{M}(D') \in S].

Here ε>0\varepsilon \gt 0 is the privacy parameter: a smaller value means a stronger guarantee. The neighbours are defined in Global Sensitivity.

A query ff is the function being released, and M\mathcal{M} is the mechanism that releases f(D)f(D) with noise. The factor eεe^{\varepsilon} comes from the Exponential Function, so e1≈2.72e^{1} \approx 2.72.

Step 1 in symbols: the true answer and its sensitivity

Write the true answer as f(D)f(D). The sensitivity is the largest change in ff between neighbours. In the ℓ1\ell_1 norm, written with a Supremum over neighbouring pairs,

Δ1f=sup⁡D∼D′∥f(D)−f(D′)∥1.\Delta_1 f = \sup_{D \sim D'} \lVert f(D) - f(D') \rVert_1.

In the walkthrough, ff is the count, so Δ1f=1\Delta_1 f = 1.

Step 2 in symbols: the Laplace noise

The Laplace mechanism releases

M(D)=f(D)+Z,Z∼Laplace(0,b),b=Δ1fε.\mathcal{M}(D) = f(D) + Z, \qquad Z \sim \mathrm{Laplace}(0, b), \qquad b = \frac{\Delta_1 f}{\varepsilon}.

Here ZZ has density 12be−∣z∣/b\frac{1}{2b} e^{-|z|/b}, as defined in the Laplace distribution lesson. The walkthrough uses b=1b = 1.

Step 3 in symbols: why the guarantee holds

Take neighbours with f(D)f(D) and f(D′)f(D') differing by at most Δ=Δ1f\Delta = \Delta_1 f. For a single output xx, the density of the release is 12be−∣x−f(D)∣/b\frac{1}{2b} e^{-|x - f(D)|/b} under DD. Divide the density under DD by the density under D′D':

e−∣x−f(D)∣/be−∣x−f(D′)∣/b=e(∣x−f(D′)∣−∣x−f(D)∣)/b≤e∣f(D)−f(D′)∣/b≤eΔ/b=eε.\frac{e^{-|x - f(D)|/b}}{e^{-|x - f(D')|/b}} = e^{(|x - f(D')| - |x - f(D)|)/b} \le e^{|f(D) - f(D')|/b} \le e^{\Delta/b} = e^{\varepsilon}.

The first inequality is the triangle inequality. Summing over outputs in a set SS gives the definition.

Check with the walkthrough: x=3.6x = 3.6, f(D)=3f(D) = 3, f(D′)=4f(D') = 4, b=1b = 1. The ratio is e−0.6/e−0.4=e−0.2e^{-0.6} / e^{-0.4} = e^{-0.2} in one direction, and e0.2≈1.22e^{0.2} \approx 1.22 in the other, which is below e1e^{1}.

Step 4 in symbols: properties that matter in practice

Two properties are used all the time. Post-processing: any function applied to an ε\varepsilon-private output is still ε\varepsilon-private, because the function cannot see the data again. Composition: answering kk queries with budgets ε1,…,εk\varepsilon_1, \dots, \varepsilon_k on the same data is at most (ε1+⋯+εk)(\varepsilon_1 + \dots + \varepsilon_k)-private under basic composition, so each release spends part of a fixed total.

Step 5 in symbols: the approximate version

The Gaussian mechanism, in Gaussian Mechanism, relaxes the guarantee to (ε,δ)(\varepsilon, \delta): the inequality above may fail with a small extra probability δ\delta, added to the right-hand side. It uses Gaussian noise, whose tails are lighter than Laplace noise, and it is often used when many queries are answered.

Worked examples

Example
Example 1: the sensitivity of a count

A dataset has 5 rows, and the count of yeses is 3.

  1. Remove one yes row: the count becomes 2. The change is 1.
  2. Remove one no row: the count stays 3. The change is 0.
  3. Add one yes row: the count becomes 4. The change is 1.
  4. Add one no row: the count stays 3. The change is 0.
  5. The largest change over all neighbours is 1, so the sensitivity is Δ1f=1\Delta_1 f = 1.

Interpretation: a count changes by at most 1 when one person is added or removed, so the noise only needs to be scaled to 1.

Example
Example 2: the effect of epsilon on the noise

The same count query, with sensitivity 1, is released with two privacy levels.

  1. With ε=0.5\varepsilon = 0.5, the scale is b=1/0.5=2b = 1 / 0.5 = 2.
  2. The chance that the noise is bigger than 1 in size is P(∣Z∣>1)=e−1/2≈0.607P(|Z| \gt 1) = e^{-1/2} \approx 0.607.
  3. With ε=2\varepsilon = 2, the scale is b=1/2=0.5b = 1 / 2 = 0.5.
  4. The same chance is P(∣Z∣>1)=e−1/0.5=e−2≈0.135P(|Z| \gt 1) = e^{-1/0.5} = e^{-2} \approx 0.135.
  5. Check: the first chance is larger, as it should be, because the first release is noisier.

Interpretation: a smaller epsilon buys stronger privacy at the price of noisier answers. Choosing epsilon is a policy decision about how much accuracy is worth giving up.

Example
Example 3: a histogram of ages in a survey

A survey of 1,000 people is split into 10 age bins. Releasing all 10 counts is a Histogram query. Adding or removing one person changes exactly one bin by 1, so the sensitivity of the whole histogram is 1. Take ε=0.5\varepsilon = 0.5.

  1. The scale is b=1/0.5=2b = 1 / 0.5 = 2, and each bin gets its own independent Laplace noise with scale 2.
  2. Releasing all 10 bins together costs ε=0.5\varepsilon = 0.5 once, because the whole histogram has sensitivity 1.
  3. For a bin whose true count is 120, the released value is 120 plus noise, so it will usually lie within a few units of 120.
  4. The probability that one bin's noise is larger than 4 in size is P(∣Z∣>4)=e−4/2=e−2P(|Z| \gt 4) = e^{-4/2} = e^{-2}.
  5. Check: e−2≈0.135e^{-2} \approx 0.135, so about one bin in seven moves by more than 4.

Interpretation: the noise is small compared with a count of hundreds, so the histogram stays useful for broad patterns, while no single person's row can be read from it. Try it: with ε=0.25\varepsilon = 0.25 instead, what is the scale per bin, and what is the probability that one bin's noise exceeds 4 in size? Answer: the scale is 4, and the probability is e−4/4=e−1≈0.368e^{-4/4} = e^{-1} \approx 0.368.

Common mistakes and tradeoffs

It is tempting to think differential privacy hides everything about a dataset. In fact it protects one person's contribution: it bounds how much that person's presence can change the output's chances. Aggregate facts about the population can still be learned, and they are the point of the release.

It is tempting to think any random noise gives privacy. In fact the noise must be scaled to the sensitivity, and the sensitivity is a worst case over all neighbouring datasets. Noise that is too small for the worst case gives no guarantee, however random it looks.

It is tempting to think answering more questions is free. In fact each release uses part of the privacy budget, and under basic composition the costs add up. A budget used up on many questions leaves little for later ones.

Differential privacy suits statistics over many people, where each person's effect is small and the noise is small too. It is the wrong tool for an exact answer about one named person, because the noise is large relative to a single record's effect and the guarantee is about inference, not secrecy. Alternatives include access controls, k-anonymity style generalisation, and synthetic data, though each has weaker or different guarantees.

History

In 2006, Cynthia Dwork and colleagues introduced the guarantee in the form used here, and showed that noise scaled to the sensitivity can achieve it. The definition gave a precise guarantee that could be reasoned about across many releases.

In 2016, Abadi and colleagues showed how to train deep networks with differential privacy, using gradient clipping and noise. That work brought the guarantee to machine learning.

Recap

  • A mechanism is ε\varepsilon-differentially private if one record changes each output's chance by at most a factor eεe^{\varepsilon}.
  • The Laplace mechanism adds noise with scale equal to the sensitivity divided by ε\varepsilon.
  • Sensitivity is the largest change in the answer from one added or removed row, taken over all neighbouring datasets.
  • Post-processing keeps the guarantee, and composition makes privacy budgets add up.
  • Read next: Gaussian Mechanism for the approximate (ε,δ)(\varepsilon, \delta) version, and Differentially Private SGD for training with it.

Check yourself

QuestionRecall: what does the sensitivity of a query measure?Show answer
The sensitivity is the largest change in the query's answer when one record is added or removed, taken over all pairs of neighbouring datasets. It sets how much noise the mechanism must add.
QuestionComputation: a count query has sensitivity 1. What is the Laplace scale for epsilon equal to 0.2, and what is the chance that the noise is larger than 5 in size?Show answer
The scale is b=1/0.2=5b = 1 / 0.2 = 5. The chance is P(∣Z∣>5)=e−5/5=e−1≈0.368P(|Z| \gt 5) = e^{-5/5} = e^{-1} \approx 0.368.
QuestionWhy: why does a smaller epsilon give a stronger guarantee?Show answer
A smaller epsilon makes eεe^{\varepsilon} closer to 1, so the output chances for two neighbouring datasets must be closer together. The mechanism must add more noise to achieve this, which is why smaller epsilon also means less accurate answers.
QuestionApplied: a team releases 20 separate counts from the same data, each with epsilon equal to 0.5. What total privacy cost should it expect, and what would it change?Show answer
Under basic composition the costs add, so the total is about 20×0.5=1020 \times 0.5 = 10, which is a weak guarantee. The team could reduce the per-query epsilon, answer fewer queries, or, if the counts are the bins of one partition of the data, release them as a single histogram query, which costs 0.5 once.

Sources