TapCub is live — analytics, insights and live chat, free on one platform
Glossary

What is k-anonymity? A worked example with generalization and l-diversity

k-anonymity means every combination of identifying columns appears at least k times. A 12-row table before and after generalization, the homogeneity attack, l-diversity and small-cell thresholds in reports.

Ethan Brooks Reviewed by Lucas Hayes Also called k anonymity Last updated Dec 3, 2026 Glossary

Quick answer

k-anonymity is a property of a released table: each combination of identifying attributes (such as age band, postcode prefix and device) appears in at least k rows, so no one can be singled out to fewer than k records using those columns. It does not by itself make data anonymous.

Formula: k = size of the smallest group of rows that share the same quasi-identifier values

What is k-anonymity?

k-anonymity is a property of a released table: every combination of identifying attributes in it appears in at least k rows. If k is 5, anyone who knows a person's age band, postcode prefix and device type still finds at least five rows that match, and cannot tell from those columns which one belongs to that person.

The model comes from Latanya Sweeney and Pierangela Samarati's work in 1998 and was set out formally in Sweeney's 2002 paper. Its starting point was a concrete failure. Medical records released without names still carried ZIP code, birth date and sex, and Sweeney linked them to a purchased voter list to find the records of the then governor of Massachusetts. Her earlier analysis of 1990 US Census summary data estimated that 87% of the US population was likely unique on 5-digit ZIP code, gender and date of birth alone.

Three points keep the definition straight:

  • k is the size of the smallest group, not the average. A table with a thousand large groups and one group of one has k = 1.
  • It is a property of the table you hand out, judged against the columns you chose. Change the columns and k changes.
  • It limits singling out. It does not, on its own, hide what the people in a group have in common.

Quasi-identifiers: which columns count

Before you can measure k you have to sort the columns. The usual split has three groups:

Column typeMeaningWebsite or support data examplesWhat to do before release
Direct identifierNames a person by itselfEmail, phone, account ID, full nameRemove
Quasi-identifierHarmless alone, identifying in combination, and findable elsewherePostcode, age, device model, signup date, city, job titleGeneralize or suppress until each combination reaches k
Sensitive attributeThe thing an attacker should not learn about a personTicket topic, plan cancellation reason, health or payment detailsCheck variety inside each group
OtherNeither of the abovePage load time bucket, report weekKeep if the question needs it

Which column is a quasi-identifier depends on what an outsider can look up. Sweeney's paper is explicit that the data holder cannot know every value held elsewhere, so the judgment is a risk decision. A practical rule: if someone outside your team could plausibly know the value about a specific person (a colleague knows your city, age and phone model), treat it as a quasi-identifier.

k-anonymity example: before and after generalization

Sample data: an export of 12 support conversations that a team wants to share with an outside consultant. Names and emails are already removed. Age, ZIP code and device are the quasi-identifiers; the conversation topic is the sensitive attribute.

RowAgeZIPDeviceTopic
12302138mobilePayment hardship
22702139mobileLogin
32902141mobileDelivery
42402142mobileLogin
53102138desktopPayment hardship
63502139desktopPayment hardship
73802141desktopPayment hardship
83302139desktopPayment hardship
94402446mobileDelivery
104702445desktopLogin
115202446mobileRefund
125802447desktopDelivery

All 12 combinations of age, ZIP and device are different, so k = 1. The consultant who knows that a particular 35-year-old on a desktop in 02139 wrote in can find row 6.

Two techniques raise k. Generalization replaces a precise value with a broader one (age 35 becomes 30–39, ZIP 02139 becomes 021). Suppression** removes a value or a whole row (device becomes \*). Applying both:

RowsAge bandZIP prefixDeviceGroup sizeTopics in the group
1–420–29021**\*4Login ×2, Payment hardship, Delivery
5–830–39021**\*4Payment hardship ×4
9–1240–59024**\*4Delivery ×2, Login, Refund

The table is now 4-anonymous. Someone who knows a person is in it, and knows their age, ZIP and device, can narrow them down to four rows at best: a one-in-four chance of picking the right row. The price is detail. Twelve distinct ages became three bands, seven ZIP codes became two prefixes, and the device column is gone, so the consultant can no longer ask whether mobile users report different problems.

The homogeneity attack and l-diversity

Look at rows 5–8 again. All four have the same topic. The consultant does not need to know which row is the 35-year-old: whichever it is, the answer is "payment hardship". This is the homogeneity attack that Machanavajjhala and colleagues described in their l-diversity paper. k-anonymity was satisfied and the sensitive fact still leaked.

l-diversity adds a second condition: each group must contain at least l well-represented values of the sensitive attribute. In the simplest "distinct" reading, count the different values per group. The table above has groups with 3, 1 and 3 distinct topics, so it is only 1-diverse.

One fix is to widen the age band. Merge the first two groups into ages 20–39:

GroupSizeDistinct topicsMost common topicShare
20–39, 021**83Payment hardship (5 rows)62.5%
40–59, 024**43Delivery (2 rows)50.0%

The table is still 4-anonymous (the smaller group has 4 rows) and now 3-diverse. It is not risk-free: across all 12 rows, 5 are payment hardship (41.7%), but for someone in the first group the observer's estimate rises to 62.5%. Counting distinct values does not stop that kind of probabilistic inference. The EU Article 29 Working Party made this point about l-diversity, and described t-closeness as a refinement that asks each group's distribution of sensitive values to resemble the distribution in the whole table.

What else k-anonymity does not stop

ProblemWhat happensCheck before release
Background knowledgeThe observer rules out values: if they know the person never orders physical goods, "Delivery" drops outAssume recipients know something about some individuals
Missing quasi-identifierA column you left in, such as exact signup time, splits groups back to size 1List every column and ask who could know it elsewhere
Complementary releaseTwo exports of the same people, generalized differently, are joined on a shared columnBase later releases on the earlier one, or treat all released columns as quasi-identifiers
Updates over timeNext month's export differs by a few rows, and the difference identifies themCompare releases, not only each file on its own
Row orderTwo files sorted the same way can be matched line by lineShuffle rows in every file
Small kWith k = 2, a recipient who knows one member has a one-in-two guess about the otherRaise k as the sensitivity rises

Sweeney's paper names the row order, complementary release and temporal cases as attacks on releases that otherwise satisfy the definition. NIST SP 800-188 states the general limit: k-anonymity and its refinements are not compositional, meaning they do not measure the combined privacy loss of several releases.

Minimum thresholds in analytics reports

The same idea shows up in aggregate reports as a minimum cell size: do not show a number if it counts fewer than a set number of people. A published rule is the US Centers for Medicare & Medicaid Services policy for its research data: no cell with a value from 1 to 10 may be reported, and no other figures may allow such a value to be derived. That policy applies to those health datasets, not to web analytics, but the second half is the part teams forget.

Sample data: visitors who started a chat, by sales region and device, with a rule of hiding cells from 1 to 10.

RegionMobileDesktopRow total
North1406146
South9588183
Column total23594329

Hiding only the 6 achieves nothing: 146 − 140 = 6. Hiding both North cells does not help either, because 235 − 95 recovers 140. With both sets of totals shown, a single small cell in a two-by-two table forces you to hide all four inner cells, or to drop a dimension and publish only the region totals (146 and 183). Decide the breakdown before looking at the numbers, and check totals, percentages and date ranges that can be subtracted from one another.

A threshold is not the same as k-anonymity. It protects the cells of one report. It does not stop someone from running a second report with a slightly different filter and subtracting the two.

k-anonymity vs anonymization and pseudonymization

These three answer different questions. Anonymization is the outcome: people can no longer be identified by reasonable means. Pseudonymization replaces identifiers with codes that can still be linked with extra information. k-anonymity is one measurable technique on the way.

k-anonymityPseudonymizationAnonymization
What it isA property of a table: groups of at least kSwapping identifiers for tokens or keyed hashesA result: identification no longer reasonably likely
Handles quasi-identifiersYes, by generalizing or suppressingNo; they usually stay as they areMust, one way or another
Rows for one person can be linkedWithin a group, only to 1 in kYes, through the tokenShould not be possible
Legal status under GDPRDepends on the remaining riskStill personal data (Recital 26)Outside the GDPR

The Article 29 Working Party's opinion on anonymisation techniques is direct about k-anonymity: it can prevent singling out, but it does not prevent inference. Reaching a chosen k therefore does not by itself make a dataset anonymous. Whether a particular release is anonymous is a legal assessment, and this page is not legal advice. For other techniques, including ones that add random noise, see privacy-enhancing technologies.

Checking k before you share analytics data

TapCub does not calculate k or l for you, so the measurement happens on the file you export. The 12-row example maps onto four steps:

  1. Classify properties. In All-platform analytics › Data › Property dictionary, run Scan now and set each property's sensitivity to direct identifier, indirect identifier or non-personal. The indirect identifiers are your candidate quasi-identifiers.
  2. Cut detail at intake where you never need it. Governance rules on the same page can block a key so it is never stored, or set a whitelist so that other values are stored as __other. These rules shape what is collected from then on; they do not rewrite old rows.
  3. Export and count. In All-platform analytics › Data › Data export (Pro or above, Analyst role or above), create an events or persons export. In a script or spreadsheet, group by your quasi-identifier columns and take the smallest group count. That number is k. Then count distinct sensitive values per group.
  4. Share less than a file when you can. If the recipient needs trends, not rows, use a read-only link from Configuration › Settings › Public sharing, with only the modules they need and a password. Visitor lists and sessions cannot be shared this way.

If a group is still too small, generalize further or leave the column out, then count again. Data you did not collect needs no k at all, which is the argument for limiting personal fields from the start.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Ethan Brooks

Solutions Engineer

Covers SDKs, API integrations, and data implementation, with an emphasis on validation, system interoperability, and troubleshooting.

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

What is an example of k-anonymity?

A support export where each combination of age band, ZIP prefix and device appears at least four times is 4-anonymous. In the 12-row sample here, exact ages and ZIP codes give k = 1; replacing them with bands and prefixes and hiding the device raises k to 4.

What value of k should you use?

No single number is right for every release. A higher k hides people better and loses more detail. Raise it when the data is sensitive, the recipients may know individuals, or the table has many columns. Some publishers set a fixed minimum cell, such as the CMS rule against reporting values from 1 to 10.

What is the difference between k-anonymity and l-diversity?

k-anonymity requires each group of look-alike rows to have at least k members. l-diversity also requires each group to contain at least l well-represented sensitive values. Without it, a group where everyone shares the same value reveals that value even though no single row can be picked out.

Is k-anonymous data anonymous under GDPR?

Not automatically. The Article 29 Working Party's opinion says k-anonymity can stop singling out but does not stop inference. Whether people are still identifiable by means reasonably likely to be used has to be assessed for the specific release. This is not legal advice.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics