Simple Algorithm
Artificial Intelligence · Deep Layer · 28 min

Differential Privacy

A mathematical definition of privacy, and its cost.

Differential privacy is a security definition with a calculus: guarantees that compose, survive any post-processing and can be tracked across thousands of training steps. This lesson makes the definition precise through the privacy-loss random variable and hypothesis testing, builds the exponential and Gaussian mechanisms, derives advanced and Rényi composition, and ends with the accounting behind DP-SGD and the 2020 US Census.

What you’ll learn

  • Characterize (ε,δ)(\varepsilon,\delta)-DP by the privacy-loss random variable, the hockey-stick divergence and hypothesis-testing trade-offs.
  • Prove the privacy and utility guarantees of the exponential mechanism, and calibrate the Gaussian mechanism exactly.
  • Derive advanced composition and Rényi accounting, including the k\sqrt k growth of ε\varepsilon for repeated Gaussian mechanisms.
  • Analyze DP-SGD (clipping, amplification by subsampling, accounting, utility bounds) and assess the 2020 Census deployment.

What the definition says

DerivationProof
  1. 1−β=Pr⁡[M(D)∈S]≤eεPr⁡[M(D′)∈S]+δ=eεα+δ1-\beta=\Pr[M(D)\in S]\le e^\varepsilon\Pr[M(D')\in S]+\delta=e^\varepsilon\alpha+\delta

    Let the test answer "DD" on the set SS, so α=Pr⁡[M(D′)∈S]\alpha=\Pr[M(D')\in S] and 1−β=Pr⁡[M(D)∈S]1-\beta=\Pr[M(D)\in S]. The DP inequality from DD to D′D' on SS gives the first condition:

  2. 1−α=Pr⁡[M(D′)∈Sc]≤eεPr⁡[M(D)∈Sc]+δ=eεβ+δ1-\alpha=\Pr[M(D')\in S^c]\le e^\varepsilon\Pr[M(D)\in S^c]+\delta=e^\varepsilon\beta+\delta

    The inequality from D′D' to DD on the complement gives the second:

  3. Conversely, the two conditions for every SS (and both orders of every pair) are the DP inequalities themselves. □\square So no attacker, whatever it knows, can beat the two lines in the (α,β)(\alpha,\beta) plane; Attacks on Models turns this into a bound on membership inference.

Recording the whole trade-off curve, rather than two lines, gives ff-DP (Dong, Roth & Su, 2022). Its central case, μ\mu-Gaussian DP, says that telling DD from D′D' is at least as hard as telling N(0,1)\mathcal N(0,1) from N(μ,1)\mathcal N(\mu,1). The Gaussian mechanism with ℓ2\ell_2 sensitivity Δ\Delta and noise σ\sigma is exactly (Δ/σ)(\Delta/\sigma)-GDP, and GDP composes by μ=μ12+⋯+μk2\mu=\sqrt{\mu_1^2+\cdots+\mu_k^2}.

Three modeling choices sit inside every guarantee. Neighbors: under add/remove a histogram has ℓ1\ell_1 sensitivity 1; under replace-one it has 2. The unit of privacy: a guarantee per record says little about a user with a thousand records, so training on user data needs user-level clipping or group privacy. δ\delta: a mechanism that publishes each record with probability δ\delta is (0,δ)(0,\delta)-DP, so δ\delta must be far below 1/n1/n.

Check your understanding

A mechanism over a database of 100,000 people is certified (1,10−3)(1,10^{-3})-DP. What is the main weakness of this guarantee?

  1. ε=1\varepsilon=1 is too large to mean anything
  2. Nothing: 10−310^{-3} is a small probability
  3. δ\delta is 100 times larger than 1/n1/n, so the definition permits releasing about 100 people's records in the clear
  4. (ε,δ)(\varepsilon,\delta)-DP does not compose
Show the answer

C. δ\delta is 100 times larger than 1/n1/n, so the definition permits releasing about 100 people's records in the clear

Publishing each record independently with probability 10−310^{-3} satisfies (0,10−3)(0,10^{-3})-DP, and hence (1,10−3)(1,10^{-3})-DP, while exposing about 100 people completely. Meaningful guarantees use δ≪1/n\delta\ll1/n, such as 10−510^{-5} or 10−1010^{-10} here.

Mechanisms beyond Laplace

DerivationProof
  1. Pr⁡[r∣D]Pr⁡[r∣D′]=exp⁡(εu(D,r)/2Δu)exp⁡(εu(D′,r)/2Δu)⋅Z(D′)Z(D)≤eε/2⋅eε/2=eε\frac{\Pr[r\mid D]}{\Pr[r\mid D']}=\frac{\exp\big(\varepsilon u(D,r)/2\Delta u\big)}{\exp\big(\varepsilon u(D',r)/2\Delta u\big)}\cdot\frac{Z(D')}{Z(D)}\le e^{\varepsilon/2}\cdot e^{\varepsilon/2}=e^\varepsilon

    Privacy. Between neighbors, the weight of each outcome changes by at most eε/2e^{\varepsilon/2}, and so does their sum Z(D)=∑rexp⁡(εu(D,r)/(2Δu))Z(D)=\sum_r\exp\big(\varepsilon u(D,r)/(2\Delta u)\big):

  2. Pr⁡[B]≤∣R∣ e−εc/(2Δu)\Pr[B]\le\abs{\mathcal R}\,e^{-\varepsilon c/(2\Delta u)}

    Utility. The bad set B={r:u(D,r)≤OPT−c}B=\{r:u(D,r)\le\mathrm{OPT}-c\} has at most ∣R∣\abs{\mathcal R} members, each of weight at most exp⁡(ε(OPT−c)/2Δu)\exp\big(\varepsilon(\mathrm{OPT}-c)/2\Delta u\big), while the optimal outcome alone makes Z(D)≥exp⁡(ε OPT/2Δu)Z(D)\ge\exp\big(\varepsilon\,\mathrm{OPT}/2\Delta u\big):

  3. Setting c=2Δuε(ln⁡∣R∣+t)c=\frac{2\Delta u}{\varepsilon}\big(\ln\abs{\mathcal R}+t\big) makes the right side e−te^{-t}. □\square The error grows only logarithmically with the number of outcomes. Selecting the most common of 1,000 diagnoses (uu = count, Δu=1\Delta u=1) at ε=1\varepsilon=1 returns, with probability 95% (t=3t=3), one whose count is within 2(ln⁡1000+3)≈202(\ln1000+3)\approx20 of the top.

The Gaussian mechanism f(D)+N(0,σ2I)f(D)+\mathcal N(0,\sigma^2I) uses the ℓ2\ell_2 sensitivity Δ=Δ2f\Delta=\Delta_2f. The classical calibration σ=Δ2ln⁡(1.25/δ)/ε\sigma=\Delta\sqrt{2\ln(1.25/\delta)}/\varepsilon holds only for ε<1\varepsilon<1 and is loose; Balle & Wang (2018) gave the exact condition:

f(D)+N(0,σ2I) is (ε,δ)-DP  ⟺  Φ(Δ2σ−εσΔ)−eε Φ(−Δ2σ−εσΔ)≤δf(D)+\mathcal N(0,\sigma^2I)\ \text{is}\ (\varepsilon,\delta)\text{-DP}\iff\Phi\Big(\frac{\Delta}{2\sigma}-\frac{\varepsilon\sigma}{\Delta}\Big)-e^\varepsilon\,\Phi\Big(-\frac{\Delta}{2\sigma}-\frac{\varepsilon\sigma}{\Delta}\Big)\le\delta
The left side is the hockey-stick divergence between N(0,σ2)\mathcal N(0,\sigma^2) and N(Δ,σ2)\mathcal N(\Delta,\sigma^2), the worst pair of neighbors. At ε=0\varepsilon=0 it reduces to their total variation distance.

Why Gaussian noise for learning? A clipped gradient with ∥g∥2≤C\norm{\mathbf g}_2\le C in dd dimensions can have ∥g∥1\norm{\mathbf g}_1 as large as CdC\sqrt d, so Laplace noise would need about d\sqrt d times more noise per coordinate than Gaussian noise, which pays only ln⁡(1/δ)\sqrt{\ln(1/\delta)}. And Gaussian releases compose cleanly: kk of them with sensitivity Δ\Delta are a single Gaussian release of the stacked vector, whose sensitivity is k Δ\sqrt k\,\Delta.

Composition: advanced and Rényi

DerivationAdvanced composition (Dwork, Rothblum & Vadhan, 2010): proof sketch for ε-DP steps
  1. L=∑i=1kLi,∣Li∣≤ε\mathcal L=\sum_{i=1}^k\mathcal L_i,\qquad\abs{\mathcal L_i}\le\varepsilon

    The privacy loss of an adaptive composition is the sum of the per-step losses, each bounded by ε\varepsilon given the past:

  2. E[Li∣past]=DKL(Mi(D) ∥ Mi(D′))≤ε(eε−1)\E\big[\mathcal L_i\mid\text{past}\big]=\KL\big(M_i(D)\,\|\,M_i(D')\big)\le\varepsilon\big(e^\varepsilon-1\big)

    Each step's expected loss is a KL divergence, which is small for an ε\varepsilon-DP pair:

  3. Pr⁡[L>kε(eε−1)+t]≤exp⁡(−t22kε2)\Pr\Big[\mathcal L>k\varepsilon(e^\varepsilon-1)+t\Big]\le\exp\Big(-\frac{t^2}{2k\varepsilon^2}\Big)

    The centered losses form a martingale with increments in intervals of length 2ε2\varepsilon, so the Azuma–Hoeffding inequality bounds the upper tail:

  4. ε′=ε2kln⁡(1/δ′)+kε(eε−1)\varepsilon'=\varepsilon\sqrt{2k\ln(1/\delta')}+k\varepsilon\big(e^\varepsilon-1\big)

    Choose t=ε2kln⁡(1/δ′)t=\varepsilon\sqrt{2k\ln(1/\delta')}. The loss exceeds ε′\varepsilon' with probability at most δ′\delta', which gives (ε′,δ′)(\varepsilon',\delta')-DP (add kδk\delta for (ε,δ)(\varepsilon,\delta) steps). □\square

For k=10,000k=10{,}000 queries at ε=0.01\varepsilon=0.01 with δ′=10−5\delta'=10^{-5}, basic composition gives 100 and advanced composition 5.8. For k=25k=25 at ε=0.2\varepsilon=0.2 it gives 5.9, worse than basic composition's 5: the k\sqrt k law pays off only for many small steps. The optimal composition bound can be computed exactly, but doing so is #P-hard in general (Murtagh & Vadhan, 2016). Rényi accounting is the practical middle ground.

DerivationThe √k law for repeated Gaussian releases
  1. εˉk(α)=kαΔ22σ2\bar\varepsilon_k(\alpha)=\frac{k\alpha\Delta^2}{2\sigma^2}

    Compose kk Gaussian releases, order by order:

  2. ε(δ)=min⁡β>0[a(1+β)+Lβ],β∗=L/a\varepsilon(\delta)=\min_{\beta>0}\Big[a(1+\beta)+\frac L\beta\Big],\qquad\beta^*=\sqrt{L/a}

    Convert to (ε,δ)(\varepsilon,\delta) and optimize over the order, writing α=1+β\alpha=1+\beta, a=kΔ2/(2σ2)a=k\Delta^2/(2\sigma^2) and L=ln⁡(1/δ)L=\ln(1/\delta):

  3. ε(δ)=kΔ22σ2+Δσ2kln⁡(1/δ)\varepsilon(\delta)=\frac{k\Delta^2}{2\sigma^2}+\frac{\Delta}{\sigma}\sqrt{2k\ln(1/\delta)}

    At the optimum, the dominant term grows like k\sqrt k and falls like 1/σ1/\sigma:

Predict before you look

A system makes k=100k=100 Gaussian releases, each with noise σ=10Δ\sigma=10\Delta. What ε\varepsilon does the Rényi bound give at δ=10−5\delta=10^{-5}?

Show the answer

5.3

a=100/(2⋅100)=0.5a=100/(2\cdot100)=0.5 and L=ln⁡105≈11.5L=\ln10^5\approx11.5, so ε=0.5+20.5×11.5≈0.5+4.8=5.3\varepsilon=0.5+2\sqrt{0.5\times11.5}\approx0.5+4.8=5.3. Each release alone costs about 0.48 (the classical calibration agrees), so basic composition would charge 48, and advanced composition 53, worse still because each step's ε\varepsilon is not small.

DP-SGD and the 2020 Census

DP-SGD (Privacy & Security) clips each example's gradient to norm CC, adds N(0,σ2C2I)\mathcal N(0,\sigma^2C^2I) to the sum, and samples each batch by including every example independently with probability qq. Sampling helps because an example that is not in the batch cannot leak in that step:

The Rényi divergence of the sampled Gaussian mechanism has no closed form, but for integer orders it is a finite binomial sum (Mironov, Talwar & Zhang, 2019). To leading order in small qq, with unit sensitivity and noise multiplier σ\sigma, it is εˉ(α)≈αq22(e1/σ2−1)≈αq22σ2\bar\varepsilon(\alpha)\approx\frac{\alpha q^2}{2}\big(e^{1/\sigma^2}-1\big)\approx\frac{\alpha q^2}{2\sigma^2}: sampling at rate qq acts like shrinking the sensitivity by a factor qq. Over TT steps the k\sqrt k law then gives ε≈(q/σ)2Tln⁡(1/δ)\varepsilon\approx(q/\sigma)\sqrt{2T\ln(1/\delta)}, the O(qTln⁡(1/δ)/σ)\order{q\sqrt{T\ln(1/\delta)}/\sigma} scaling of Abadi et al.'s moments accountant.

A worked case: batches with q=0.01q=0.01 (600 of 60,000 examples), σ=1.1\sigma=1.1, T=10,000T=10{,}000 steps (100 epochs) and δ=10−5\delta=10^{-5}. Summing the exact Rényi divergences over integer orders gives ε≈6.3\varepsilon\approx6.3 (best order α=5\alpha=5), and the leading-order formula gives 6.1. With σ=4\sigma=4 the same run costs ε≈1.3\varepsilon\approx1.3, at the price of much noisier gradients.

Utility. For convex, Lipschitz losses on a bounded domain, the best achievable excess empirical risk under (ε,δ)(\varepsilon,\delta)-DP is Θ~(dln⁡(1/δ)/(εn))\tilde\Theta\big(\sqrt{d\ln(1/\delta)}/(\varepsilon n)\big), and noisy SGD attains it (Bassily, Smith & Thakurta, 2014): privacy costs more in high dimension and less with more data. In practice, clipping biases the gradients (so CC is set near typical gradient norms), per-example gradients cost memory and time, tuning hyperparameters on private data leaks privacy unless it is accounted for (Papernot & Steinke, 2022), and privately fine-tuning publicly pretrained models narrows the accuracy gap substantially (De et al., 2022, for images; Li et al., 2022, for language).

The 2020 US Census. The TopDown algorithm (Abowd et al., 2022) adds discrete Gaussian noise (Canonne, Kamath & Steinke, 2020) to many tables at each level of the geographic hierarchy, from nation down to census block, then solves constrained optimization problems that return consistent, nonnegative integer tables. That second phase is post-processing and costs no privacy. The budget was set in zero-concentrated DP (Bun & Steinke, 2016): ρ=2.63\rho=2.63 for the person-level redistricting data, roughly ε≈17\varepsilon\approx17 at δ=10−10\delta=10^{-10}. State population totals were held invariant, published exactly and outside the formal guarantee. Demographers and some states objected to the noise in small areas and small groups; the Bureau pointed to its 2010 reconstruction experiment.

Key takeaways

  • (ε,δ)(\varepsilon,\delta)-DP means the hockey-stick divergence HeεH_{e^\varepsilon} between neighbors' outputs is at most δ\delta; equivalently, every test satisfies eεα+β≥1−δe^\varepsilon\alpha+\beta\ge1-\delta and α+eεβ≥1−δ\alpha+e^\varepsilon\beta\ge1-\delta; δ\delta must be far below 1/n1/n.
  • The exponential mechanism selects privately with error 2Δuε(ln⁡∣R∣+t)\frac{2\Delta u}{\varepsilon}(\ln\abs{\mathcal R}+t); the Gaussian mechanism is calibrated exactly by the Balle–Wang condition and suits ℓ2\ell_2-bounded vectors.
  • Basic composition adds ε\varepsilon's; advanced composition grows like k\sqrt k for small steps; Rényi DP adds order by order, and kk Gaussian releases cost ε≈kΔ22σ2+Δσ2kln⁡(1/δ)\varepsilon\approx\frac{k\Delta^2}{2\sigma^2}+\frac\Delta\sigma\sqrt{2k\ln(1/\delta)}.
  • DP-SGD combines clipping, Gaussian noise and Poisson sampling (amplification ln⁡(1+q(eε−1))\ln(1+q(e^\varepsilon-1)); to leading order, sensitivity scaled by qq) with numerical Rényi accounting; convex utility is Θ~(d/(εn))\tilde\Theta\big(\sqrt d/(\varepsilon n)\big).
  • The 2020 Census used TopDown with zero-concentrated DP (ρ=2.63\rho=2.63 for persons, roughly ε≈17\varepsilon\approx17 at δ=10−10\delta=10^{-10}) plus exact invariants: DP at national scale, with real trade-offs.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why does the exponential mechanism weight outcomes by exp⁡(εu/(2Δu))\exp\big(\varepsilon u/(2\Delta u)\big) rather than exp⁡(εu/Δu)\exp\big(\varepsilon u/\Delta u\big)?

  1. To make the probabilities sum to one
  2. Because the utility of the best outcome counts twice
  3. To improve accuracy
  4. Because both an outcome's weight and the normalizing sum can change by eε/2e^{\varepsilon/2} between neighbors, and the two factors multiply
Show the answer

D. Because both an outcome's weight and the normalizing sum can change by eε/2e^{\varepsilon/2} between neighbors, and the two factors multiply

The probability is a ratio of the outcome's weight to the total weight, and a neighboring dataset can move the numerator up while moving the denominator down, each by at most eε/2e^{\varepsilon/2}; together they stay within eεe^\varepsilon.

Question 2

A system makes many Gaussian releases with σ≫Δ\sigma\gg\Delta. Holding kk and δ\delta fixed, roughly how does ε\varepsilon change if you double σ\sigma?

  1. It falls by a factor of about 4
  2. It falls by a factor of about 2
  3. It falls by a factor of about 2\sqrt2
  4. It does not change
Show the answer

B. It falls by a factor of about 2

For σ≫Δ\sigma\gg\Delta the dominant term is Δσ2kln⁡(1/δ)\frac\Delta\sigma\sqrt{2k\ln(1/\delta)}, linear in 1/σ1/\sigma. The quadratic term kΔ2/(2σ2)k\Delta^2/(2\sigma^2) does fall by 4, but it is the smaller one.

Question 3

A mechanism is 11-DP. You run it on a Poisson subsample that includes each record with probability q=0.01q=0.01. What privacy guarantee results?

  1. ε=1\varepsilon=1: subsampling changes nothing
  2. ε=0.1\varepsilon=0.1
  3. ε=ln⁡(1+0.01(e−1))≈0.017\varepsilon=\ln\big(1+0.01(e-1)\big)\approx0.017
  4. ε=0.0001\varepsilon=0.0001
Show the answer

C. ε=ln⁡(1+0.01(e−1))≈0.017\varepsilon=\ln\big(1+0.01(e-1)\big)\approx0.017

Amplification by subsampling gives ln⁡(1+q(eε−1))=ln⁡(1.0172)≈0.017\ln\big(1+q(e^\varepsilon-1)\big)=\ln(1.0172)\approx0.017, close to qε=0.01q\varepsilon=0.01 because ε\varepsilon is moderate. A record that is probably not sampled can rarely affect the output.

Question 4

The Census TopDown algorithm turns noisy counts into consistent, nonnegative integer tables. How much of the privacy budget does that step consume?

  1. None: it is post-processing of noisy measurements and never touches the confidential data
  2. Half the budget, because it runs on every level of geography
  3. An amount equal to the number of constraints
  4. It makes the release non-private, because rounding removes noise
Show the answer

A. None: it is post-processing of noisy measurements and never touches the confidential data

The optimization uses only the noisy measurements, so post-processing preserves the guarantee. The exceptions are the invariants, such as state population totals, which were published exactly and lie outside the formal guarantee.

Further reading

  • C. Dwork & A. Roth, The Algorithmic Foundations of Differential Privacy (Foundations and Trends in Theoretical Computer Science, 2014).
  • F. McSherry & K. Talwar, "Mechanism design via differential privacy," FOCS (2007).
  • C. Dwork, G. N. Rothblum & S. Vadhan, "Boosting and differential privacy," FOCS (2010).
  • I. Mironov, "Rényi differential privacy," IEEE Computer Security Foundations Symposium (2017).
  • J. M. Abowd et al., "The 2020 Census Disclosure Avoidance System TopDown Algorithm," Harvard Data Science Review (2022).