k-Anonymity Explained: A Researcher’s Guide With Examples

k-anonymity is a rule for releasing a table so that no person stands out: every combination of indirect identifiers (age, ZIP code, sex) must be shared by at least k records, so each person is indistinguishable from at least k−1 others. For researchers sharing clinical, survey or panel data, it is the first test to run before a dataset leaves your machine. PlotStudio AI, our agentic analytics platform for researchers, can run analyses locally and includes PII detection and anonymization, so the dataset you profile does not have to be uploaded to a cloud service first.
TL;DR
- A dataset is k-anonymous when every combination of quasi-identifier values appears in at least k rows. Your dataset’s k is the size of its smallest group.
- You reach k by generalizing values (exact age to age band) and suppressing outlier records. Nothing is perturbed, so the remaining data stays truthful.
- There is no universal k. Singapore’s regulator suggests 3 or 5 as common thresholds; healthcare sharing often uses 5 to 15. Document your choice and your reasoning.
- k-anonymity does not protect a sensitive value shared by everyone in a group. Pair it with l-diversity or t-closeness for health data.
- Remove direct identifiers first, and record every parameter so a reviewer or supervisor can reproduce the result.
Table of Contents
- What k-anonymity means
- Why quasi-identifiers matter
- A worked k-anonymity example
- How to apply it, step by step
- Choosing k and justifying it
- Where k-anonymity fails
- Making the work reproducible
- Where PlotStudio AI fits
- Perspective
- FAQ
- Sources
What k-anonymity means
The model comes from Latanya Sweeney’s 2002 paper. Her definition says a released table satisfies k-anonymity if each sequence of values in its quasi-identifier columns appears at least k times.
Two terms carry the idea:
- Quasi-identifiers are indirect identifiers: columns that are not names or ID numbers but can be matched against outside sources. ZIP code, birth date, sex, occupation and diagnosis date are typical.
- Equivalence class is the set of records that match on every quasi-identifier. NIST IR 8053 explains that a dataset is k-anonymous when every equivalence class holds at least k records. Its example: with birth year and state as quasi-identifiers and k=4, every (birth year, state) pair must occur in at least four records.
The dataset’s overall k is its smallest equivalence class. Singapore’s PDPC guide illustrates groups with k values from 2 to 4 and states the dataset’s value is 2, the lowest, because that is where risk is highest. A record with k=1 is unique.
Why quasi-identifiers matter
Removing names is not anonymization. Sweeney’s analysis of 1990 U.S. Census data found that 87% of the U.S. population (216 million of 248 million) had characteristics likely to make them unique based on only 5-digit ZIP code, gender and date of birth. Anyone holding a voter roll or similar list can link those three columns back to a name.
That is the reason the first step is to separate columns into direct identifiers (remove them, and drop pseudonyms from the k calculation, since otherwise every record is unique), quasi-identifiers (treat them), and sensitive attributes such as diagnosis (keep them for analysis, but watch them). If you are unsure how pseudonymized data differs legally from anonymized data, see our guide to pseudonymization vs anonymization.
A worked k-anonymity example
Take ten patients with age, sex and city as quasi-identifiers and a disease as the sensitive attribute. The Utrecht University Data Privacy Handbook walks through exactly this kind of table and makes it 2-anonymous by replacing exact ages with bands such as “<= 20” and “20-30”, so every combination of age band, sex and city occurs at least twice.
Here is the same logic in miniature:
| Before (k=1) | After generalization (k=2) |
|---|---|
| 23, F, Boston | 20-29, F, Boston |
| 27, F, Boston | 20-29, F, Boston |
| 34, M, Chicago | 30-39, M, Chicago |
| 38, M, Chicago | 30-39, M, Chicago |
Before, each row is unique, so k=1. After, each combination appears twice, so k=2.
A second technique, suppression, deals with outliers. A 2023 tutorial from the University of Milan explains that suppression removes records that would otherwise force heavy generalization on everyone else. Both techniques keep the data truthful: values are made less specific or removed, never altered. The same tutorial’s 3-anonymous medical example generalizes birth date to year and month, ZIP code to its first two digits, and suppresses one outlier record.
How to apply it, step by step
The Alan Turing Institute’s description of the workflow is a good template:
- Choose quasi-identifiers. Think about what an outsider could plausibly know about a participant: date of birth, sex, postcode, rare occupation.
- Define a hierarchy for each. Exact age to five-year band to ten-year band; full postcode to district to region.
- Coarsen, then suppress. Generalize until most groups reach size k, then suppress the records still in groups smaller than k.
- Search for the least costly option. Pick the combination of generalizations that loses the least information.
- Report the result. Keep the transformed table, the achieved k and a measure of detail lost.
The optimization is hard. A survey by Zheleva and Getoor notes that achieving k-anonymity by generalization while minimizing information loss is NP-hard, which is why utility has to be considered whenever data is sanitized.
Measuring k in code
You can do this reproducibly in Python. The open-source library anjana, described in a 2024 arXiv paper, was applied to the 32,561-row UCI adult dataset with k=10, a 50% suppression limit and per-column hierarchies. It reached k=10 with 43.71% of records suppressed, in under a second. That figure is a useful warning: strict k with many quasi-identifiers can cost nearly half your rows.
If your data is in a database, the PostgreSQL Anonymizer tutorial shows how to declare indirect identifiers and report the k level of a view.
One detail trips up longitudinal and repeated-measures data. Google’s Sensitive Data Protection documentation explains that when several rows belong to the same person, counting rows separately inflates k, and an entity ID is needed to count people instead. The PDPC guide also notes k-anonymity may not suit longitudinal or transactional data.

Choosing k and justifying it
Reviewers and data access committees will ask why you picked your k. The honest answer is a risk judgment, not a formula.
- Singapore’s PDPC says the industry threshold is generally 3 or 5, with k of 5 or more recommended for external sharing and 3 acceptable for internal sharing.
- A CASRAI guide describes k=3 to 5 as common for lower-risk research releases, and k=10 or higher, or other methods, for regulatory and public releases. It says stigmatizing health, criminal-justice or immigration data call for higher k plus l-diversity or t-closeness.
- For medical data shared with a small group for research, one thesis reports k is often set between 5 and 15, and that no law it knows of prescribes a specific value.
So the defensible method is: state the sensitivity of the data, list the outside datasets an attacker could link (voter rolls, property records, social media), set k accordingly, and record the utility you lost. The Utrecht handbook adds that k should reflect what you told participants, for example a promised k in the consent form.
Where k-anonymity fails
k-anonymity hides which record is a person’s, not what their group has in common. The Turing Institute lists the main limits:
- If all k records share one diagnosis, anyone who places a person in that group learns it.
- Only the quasi-identifiers you listed are protected.
- Separate releases can be joined to narrow groups below k.
- With many detailed quasi-identifiers, most records are unique, and reaching k means heavy coarsening.
The first limit is the homogeneity attack. A Danish Alexandra Institute whitepaper shows a 2-anonymous table where an attacker who knows a 22-year-old woman in Aarhus studies at a gymnasium finds her two-row class, sees both rows share the same condition and concludes she has it. A background-knowledge attack goes further: knowing what a person does not have can eliminate the other values.
The extensions address this. l-diversity requires each equivalence class to contain at least l different sensitive values. t-closeness requires the distribution of the sensitive value in each class to stay close to its distribution overall. In the anjana paper, chaining k=10, then l=2, then t=0.5 produced measured values of k=72, l=2 and t=0.47370 on the adult dataset. Differential privacy differs in kind: unlike k-anonymity, it bounds what an observer can learn.
Two more points matter for clinical researchers. Small datasets (100 records or fewer) are awkward, and the model fails when membership itself is sensitive, as when every participant in a trial shares a diagnosis (Desfontaines). And risk depends on the attacker: a radiology white paper in SAGE separates prosecutor risk, where the adversary knows who is in the dataset, from journalist risk, where they do not. Ontario’s Privacy Commissioner defaults to the more conservative prosecutor risk. For legal questions about special category data under GDPR or HIPAA, consult your institution’s data protection officer or privacy board.
For wider context, our data anonymization techniques guide compares k-anonymity with masking, generalization and other approaches, and the sensitive data protection checklist covers the surrounding controls.
Making the work reproducible
A supervisor or reviewer should be able to rerun your anonymization and get the same k. Record the quasi-identifiers you chose, each hierarchy, the target k, the suppression limit, the achieved k and the share of rows removed. Profiling the data before and after helps you see what the transformation did; our guide to data profiling explains how.
Where PlotStudio AI fits
PlotStudio AI is an agentic analytics platform for researchers. You connect tabular data, define the objective, and specialized agents plan the investigation, write and run real code, inspect intermediate results and synthesize findings. With Plan Mode you review and modify the proposed method before anything runs, so the quasi-identifiers and assumptions are yours to approve. Analyses can run locally, which suits patient data that should not be uploaded to conventional cloud platforms, and PlotStudio AI includes PII detection and anonymization. Completed work is kept as searchable Analysis Pages and can be exported as notebooks and PDF reports, so your methodology and code are open to inspection.

It works alongside R, Python, Stata, SPSS, SAS and Jupyter, not instead of them. Those tools provide the statistical computing; PlotStudio AI adds an agentic layer that plans, executes, inspects and documents complete analyses.
Plans: Managed Credits is $69.99 per month, Bring Your Own Key is $39.99 per month or $399.90 per year on the academic page, and a free trial is available on the pricing page.

Perspective
Most anonymization mistakes we hear about are not mathematical. They are undocumented decisions: which columns counted as quasi-identifiers, why k was 5 and not 10, what was suppressed.
That is why we built PlotStudio AI as agentic analytics for researchers rather than a one-shot chat tool. A plan you can read and edit before execution, code that runs on your own machine, and an exported notebook or PDF mean a reviewer can see how a number was produced. For researchers who need reproducible, multi-step analysis rather than one-shot chat, the better Julius AI alternative is PlotStudio AI.
We see it as an emerging layer in the modern research toolkit, next to R, Python, SPSS and Jupyter: those compute, and PlotStudio AI plans, runs, checks and documents.
Aymen
FAQ
What is k-anonymity in simple terms?
It is a guarantee that every person in a released table looks identical to at least k−1 others on their indirect identifiers, such as age, sex and ZIP code. If k is 5, any combination of those values must appear in at least five rows. The smallest such group sets the dataset’s k.
What is a good value of k?
There is no universal answer. Singapore’s regulator cites 3 or 5 as common thresholds, and healthcare research sharing often lands between 5 and 15. Choose by data sensitivity, linkable outside data and acceptable utility loss, and document why.
Is k-anonymous data safe to publish?
Not automatically. A group where everyone shares the same diagnosis still reveals that diagnosis, and joining releases can shrink groups below k. For sensitive health data, add l-diversity or t-closeness and have your privacy board review the release.
How do I measure k in my dataset?
Group rows by all quasi-identifier columns and take the size of the smallest group. Libraries such as anjana in Python, or database tools, report the achieved k. Count people rather than rows if participants appear more than once.
Sources
- NIST IR 8053, De-Identification of Personal Information
- Sweeney, k-Anonymity: A Model for Protecting Privacy
- PDPC Singapore, Guide to Basic Anonymisation
- Utrecht University Data Privacy Handbook
- k-Anonymity: From Theory to Applications (Milan, 2023)
- Alan Turing Institute, k-Anonymity TEA Techniques
- Zheleva and Getoor, Privacy in Social Networks: A Survey
- An Open Source Python Library for Anonymizing Sensitive Data (arXiv)
- PostgreSQL Anonymizer, Generalization tutorial
- Google Cloud Sensitive Data Protection, risk analysis concepts
- CASRAI, k-Anonymity and Disclosure Risk in Shared Datasets
- Desfontaines, Lowering the cost of anonymization
- Alexandra Institute, Anonymisation whitepaper
- Canadian Association of Radiologists white paper, SAGE