Anonymizing a Dataset: Masking, Hashing and k-Anonymity

Why hashing an email column is pseudonymization, not anonymization, and how to generalize ZIP codes and birth dates until every row hides in a group of k.

By · · 11 min read

Illustration for Anonymizing a Dataset: Masking, Hashing and k-Anonymity

You have a customer export with names, emails, ZIP codes and birth dates, and someone wants it for analysis, a vendor or a public sample. To anonymize it you must remove the direct identifiers (name, email, phone) and then coarsen the indirect ones (ZIP code, birth date, sex) until no row is unique on them. Hashing the email column does not count: a hash is the same every time, so anyone who can guess the input can match it, which makes hashed data pseudonymized, not anonymous, under the GDPR and the UK ICO's guidance.

This post works through both halves with a small table. It is a practical introduction, not legal advice: if the data is health, financial or children's data, or the release is public, involve your data protection officer or privacy counsel before it leaves your hands.

Pseudonymization vs anonymization

The two words sound alike and have very different legal consequences.

Pseudonymization replaces identifiers with something else (a hash, a token, a random ID) while the link back to the person still exists somewhere. Article 4(5) of the GDPR defines it as processing so that data "can no longer be attributed to a specific data subject without the use of additional information", where that additional information is kept separately and protected. Recital 26 says pseudonymized data that could be re-attributed with additional information is still personal data. It is a security measure, and a good one, but all of the GDPR still applies.

Anonymization means no one can reasonably identify a person from the data, taking into account "all the means reasonably likely to be used", including singling a person out. Recital 26 says the GDPR does not apply to anonymous information at all. The UK ICO's guidance, finalised in March 2025, uses the same line and adds a practical test: could a "motivated intruder", a reasonably competent person with no prior knowledge of the people in the data but with access to resources such as the internet and public records, re-identify anyone?

The Article 29 Working Party (now the European Data Protection Board) put it bluntly in its 2014 opinion on anonymization techniques: pseudonymization "is a useful security measure but not a method of anonymisation".

One recent refinement: in September 2025 the EU Court of Justice ruled in EDPS v SRB (C-413/23 P) that pseudonymized data is not automatically personal data for a recipient who has no realistic way to re-identify it. It stays personal data for whoever holds the key. That ruling turns on the recipient's actual means, so it is not a shortcut you can claim for a hashed export without careful analysis.

Why a hashed email is still personal data

A cryptographic hash such as SHA-256 is one-way: you cannot compute the input from the output. But it is also deterministic: the same input always gives the same output. That second property is the problem.

Hash ana.lopez@example.com with SHA-256 in the Hash Generator and you get:

53fdd27c13c87b89296422dd99e14d02656dbcacefed01d3b53a56313adf3a98

Anyone who has a list of email addresses, a marketing partner, a data broker or an attacker with a breach dump, can hash every address on their list and look for a match. The Working Party's opinion describes exactly this: if the range of input values is known, they "can be replayed through the hash function". Emails, phone numbers and national ID numbers are all easy to enumerate or already circulate in lists. This is also why ad platforms ask for hashed emails for audience matching: the hash is designed to be matched.

Three things follow:

  • Plain hashing is pseudonymization. Treat the output as personal data.
  • A salt or key helps against outsiders, not against you. A keyed hash such as HMAC-SHA-256, made with the HMAC Generator and a secret kept away from the dataset, stops someone without the key from replaying a list. Whoever holds the key can still re-link, so it remains pseudonymization.
  • Normalize before hashing. Ana.Lopez@example.com (capital letters and a trailing space) hashes to dad422d65c801c2f974e46c17beb37f31f8eadd21fdf1cb2674b8a18079c7c3b, a completely different value. If two systems normalize differently, their hashes never join. Lower-case and trim first, and check the column with the Find Duplicate Entries tool with "Case sensitive" off (the default): on a list holding ana.lopez@example.com, Ana.Lopez@example.com and lee.park@example.com, it reports one duplicate entry, the two Ana rows, which would have hashed apart.

Quasi-identifiers and the Sweeney result

Removing names and emails is the easy part. The harder part is what Latanya Sweeney called quasi-identifiers: columns that are not identifying on their own but are in combination.

In her 2002 paper on k-anonymity, Sweeney describes buying the voter list for Cambridge, Massachusetts for twenty dollars and linking it to hospital data that had been released with names removed but ZIP code, birth date and sex kept. The governor of Massachusetts at the time, William Weld, lived in Cambridge. According to the voter list, six people shared his birth date, only three were men, and he was the only one in his five-digit ZIP code. The paper also cites her earlier finding that 87% of the US population (216 million of 248 million) were likely unique on five-digit ZIP, gender and date of birth alone.

That is why "we removed the names" is not anonymization. Any column an outsider could also know (location, birth date, sex, job title, employer, admission date) is a quasi-identifier.

Worked example: getting a table to k-anonymity

A table is k-anonymous when every combination of quasi-identifier values appears in at least k rows. Each person then hides in a group of at least k people who look identical on the columns an attacker could link. The two standard moves are generalization (make values coarser) and suppression (remove rows or cells that will not fit).

Start with eight patient rows. Names and emails are already deleted; the quasi-identifiers are ZIP, birth date and sex, and diagnosis is the sensitive value.

ZIPBirth dateSexDiagnosis
021381984-03-11FAsthma
021391986-07-02FDiabetes
021411981-12-19FAsthma
021381983-05-30MHypertension
021421987-09-14MAsthma
021391972-01-08MDiabetes
021411975-06-21MMigraine
021381978-10-03FHypertension

Measure k. Put the quasi-identifier columns of each row on one line, such as 02138, 1984-03-11, F, paste the eight lines into Find Duplicate Entries, switch off "Only duplicates" so lines that appear once are listed too, and leave "Show count in result" on. Every line "appears 1 time": eight unique rows, so k = 1. Each person is singled out.

Generalize. Truncate the ZIP to its first three digits (021**) and replace the birth date with the birth decade. The lines become 021**, 1980s, F and so on. Run them through the tool again:

  • 021**, 1980s, F appears 3 times
  • 021**, 1980s, M appears 2 times
  • 021**, 1970s, M appears 2 times
  • 021**, 1970s, F appears 1 time

The smallest group decides k, so the table is still only 1-anonymous: the one woman born in the 1970s is unique.

Group sizes for the eight-row example: before generalization every row is its own group of 1; after coarsening ZIP and birth date the groups are 3, 2, 2 and 1, so k stays 1; dropping sex gives groups of 5 and 3 for k equals 3, while suppressing the single outlier row instead gives groups of 3, 2 and 2 for k equals 2
Group sizes for the eight-row example: before generalization every row is its own group of 1; after coarsening ZIP and birth date the groups are 3, 2, 2 and 1, so k stays 1; dropping sex gives groups of 5 and 3 for k equals 3, while suppressing the single outlier row instead gives groups of 3, 2 and 2 for k equals 2

Choose: suppress or generalize further. You now have two honest options.

  1. Suppress the outlier. Delete that one row. The remaining seven lines form groups of 3, 2 and 2, so k = 2, and the sex column survives.
  2. Generalize sex away. Drop the sex column. The eight lines form two groups, 021**, 1980s (5 times) and 021**, 1970s (3 times), so k = 3 and no rows are lost.

Which is better depends on the analysis: a study of sex differences needs option 1, while a count by decade keeps every row with option 2. Real tables run the same loop with more rows and more columns: measure, coarsen the column that splits groups most, re-measure.

Check the sensitive column. k-anonymity only protects identity, not the attribute. If every person in a group had the same diagnosis, knowing someone is in the group would reveal it. Here the 1980s women share asthma, diabetes and asthma, so the group does not give a single answer, but in larger releases this "homogeneity" problem is common and is what extensions such as l-diversity address.

For US health data, note that the HIPAA Privacy Rule's Safe Harbor method has its own fixed list: among other things it allows only the first three ZIP digits (and only where that three-digit area has more than 20,000 people) and removes every date element except the year. The example's choices happen to fit, but check the rule itself before relying on it.

Data masking techniques at a glance

TechniqueWhat it doesResult
SuppressionDeletes a column, a row or a cellCan anonymize if enough is removed
GeneralizationCoarsens values (ZIP to 3 digits, date to year or decade)Main tool for k-anonymity
Partial maskingHides part of a value (a***@example.com)Display safety; usually still personal data
HashingReplaces a value with a deterministic digestPseudonymization
Keyed hashing or tokensReplaces with a value only the key holder can re-linkPseudonymization
AggregationPublishes counts or averages instead of rowsOften anonymous if small cells are suppressed

The GDPR's data minimisation principle in Article 5(1)(c) points the same way as all of this: keep only the columns the analysis needs. A column you never export never needs masking.

Tools for this job

  • Hash Generator: produce SHA-256 or SHA-3 digests of identifiers for pseudonymized joins, and see for yourself that the same input always gives the same hash.
  • Find Duplicate Entries: measure k by counting how often each quasi-identifier combination appears, and catch case and whitespace variants before you hash.
  • HMAC Generator: build keyed hashes when a partner must not be able to replay a list of known emails.
  • Remove Duplicate Lines: list the distinct combinations once you have generalized, to see how many groups you have.

Related reading: hash algorithms compared explains why SHA-256 is one-way but not secret, and HMAC signatures explained covers how keyed hashes work. The hash generator guide walks through the tool itself.

Frequently asked questions

Is a hashed email address personal data under the GDPR?

Yes, for anyone who can re-link it. A plain hash is deterministic, so anyone with a list of addresses can hash them and match. Recital 26 of the GDPR treats pseudonymized data as personal data, and the ICO and the Article 29 Working Party both class hashing as pseudonymization.

What value of k is enough for k-anonymity?

There is no legal number. k is a property of the table, and the right value depends on how many people an attacker could plausibly know, what the data reveals and who receives it. Pick k as part of a documented risk assessment, and check the sensitive columns as well as k itself.

Does adding a salt make hashed data anonymous?

No. A secret salt or key stops outsiders from replaying a list through the hash, but whoever holds it can still re-identify every row. That is pseudonymization with better security, and the data stays personal data for the key holder.

Can anonymized data become personal data again?

Yes. Anonymization is judged against the means reasonably likely to be used, and those change: a new public dataset can make old quasi-identifiers linkable. The ICO's guidance treats identifiability as context-specific and able to change as technology and other available data change, so review the risk before a dataset is shared again.

Sources and further reading

Browse all tools