Front Matter#
This book offers a hands-on introduction to differential privacy, combining formal foundations with executable code and practical design patterns.
The material has evolved through lecture notes, workshops, and collaborations with academics and practitioners, gradually expanding to cover both classical and modern topics.
We are grateful to the many contributors—readers, reviewers, and colleagues—whose questions, suggestions, and corrections have shaped this book.
Abstract#
This book provides a comprehensive, example-driven introduction to differential privacy through the lens of practical programming. Bridging the gap between theory and implementation, it walks readers through core mechanisms, such as the Laplace and Exponential mechanisms, smooth sensitivity, sample-and-aggregate, and the sparse vector technique, all while grounding each in executable Python examples. With an emphasis on hands-on learning and reproducibility, the material is designed for learners who wish to move beyond abstract definitions and understand how differential privacy is applied to real datasets, models, and systems.
The chapters of this book are organized around both foundational theory and practical concerns: sensitivity and composition are introduced early, followed by in-depth treatments of de-identification, synthetic data generation, and private machine learning. The book also includes discussion of subtle implementation challenges such as efficiency, numerical stability, privacy accounting, and optimizations like ghost clipping. Wherever possible, examples use familiar tools like pandas, numpy, and matplotlib to increase clarity with data scientists.
By making privacy-preserving algorithms concrete and programmable, the book aims to lower the barrier to entry for researchers, engineers, and educators working with sensitive data. It is intended as both a self-contained reference and a foundation for further exploration into formal privacy and responsible AI.
Evolution#
We welcome feedback of all kinds—on structure, missing or excessive material, unclear explanations, potential exercises, as well as any errors or typos.
The book is maintained on GitHub, and contributions via pull requests are encouraged.
If you have suggestions, plans, questions, or general thoughts, feel free to reach out to either author via email.
Acknowledgements#
For pull requests big and small, and expert translation, we would like to thank all our contributors!
Background Resources: Discrete Mathematics and Probability#
This book assumes some familiarity with basic concepts from discrete mathematics and probability theory. If it’s been a while since you’ve encountered these topics, or if you’re new to them, the following resources offer excellent introductions and refreshers. While not exhaustive, this list emphasizes texts and courses that are widely used, accessible to programmers, and well-aligned with the material in this book.
Discrete Mathematics#
Many of the privacy techniques we’ll explore involve reasoning about sets, functions, relations, and graphs. You’ll also encounter formal logic and proofs, especially when we define privacy guarantees precisely. To build or reinforce your foundations, here are some options:
Discrete Mathematics and Its Applications, Kenneth H. Rosen
A comprehensive and widely used textbook. Covers all the essentials: logic, proof techniques, set theory, combinatorics, and graph theory. Suitable for self-study or classroom use. [1]Mathematics for Computer Science, Eric Lehman, Tom Leighton, and Albert R. Meyer (MIT)
A free textbook developed for MIT’s introductory discrete math course. It blends theoretical depth with clarity. Great for students with programming experience. [2] Download PDFDiscrete Mathematics: An Open Introduction, Oscar Levin
A free and open-source text that offers an intuitive and example-driven approach to logic, induction, and modular arithmetic. [3] Online book
Probability#
Privacy techniques like the Laplace and Gaussian mechanisms rely on randomized algorithms, and a firm understanding of probability will help you make sense of how (and why) these methods work.
A First Course in Probability, Sheldon Ross
A classic introduction. Covers the fundamentals with clear explanations and many examples. Particularly strong on discrete random variables and distributions. [4]Introduction to Probability, Dimitri P. Bertsekas and John N. Tsitsiklis
Used in MIT courses, this book emphasizes intuition alongside rigorous analysis. Excellent for learning both theory and applications. [5]Introduction to Probability, Charles Grinstead and J. Laurie Snell
A highly readable and freely available textbook. Especially good for beginners or those looking to brush up. [6] Download PDF
A Note on Prerequisites#
You don’t need to be a mathematician to understand differential privacy — but a bit of mathematical thinking will go a long way. If you’re already comfortable with Python, NumPy, and Pandas (as this book assumes), you’re more than capable of picking up any background math you need on the road!