De-identification is the work of turning a dataset about identifiable
people into one that cannot reasonably be traced back to them, while
keeping it useful. Removing names alone never achieves that. A
combination of postcode, birth date, and gender can single out most
people, and a "de-identified" extract joined against a public dataset
can quietly re-identify the whole file. This sub-skill covers the
practical pipeline - find every identifier, transform the risky ones,
measure what remains, and attack your own output before anyone else
gets it.
Quick Workflow
- Classify every column - direct identifier, quasi identifier,
sensitive attribute, or non-identifying.
- Drop direct identifiers outright, unless a keyed pseudonym is
genuinely needed for linkage, in which case protect the key.
- Generalize quasi identifiers - age bands instead of birth dates,
regions instead of postcodes - until equivalence classes are big
enough.
- Suppress or perturb the records that still stand out, and record
how many rows were affected.
- Measure k-anonymity on the quasi identifiers and check that
sensitive attributes are diverse within each group.
- Attack your own output - attempt linkage against plausible public
or partner datasets, and record the success rate.
- Ship with a data sharing agreement that bans re-identification
attempts, and keep the mapping key separate from the extract.
1. Classify identifiers in a dataset
#!/usr/bin/env python3
"""Identifier classification - direct, quasi, sensitive, or safe."""
import csv
from collections import Counter
DIRECT = {"name", "email", "phone", "national_id", "customer_id"}
QUASI = {"postcode", "birth_date", "gender", "city", "job_title"}
SENSITIVE = {"diagnosis", "salary", "political_view", "religion"}
with open("extract.csv", newline="") as fh:
reader = csv.DictReader(fh)
for column in reader.fieldnames:
if column in DIRECT:
kind = "DIRECT - drop or keyed pseudonym"
elif column in QUASI:
kind = "QUASI - generalize and check group sizes"
elif column in SENSITIVE:
kind = "SENSITIVE - check diversity within each group"
else:
kind = "non-identifying - keep"
print(f"{column:15s} {kind}")
2. Generalize and pseudonymize
Generalization trades precision for safety, and the trade must be
deliberate per column. Pseudonyms must be keyed and one way - a
sequential fake id, or a hash without a secret, is reversible by
anyone who guesses the scheme.
#!/usr/bin/env python3
"""Generalization plus keyed pseudonyms for a sample extract."""
import hashlib
import hmac
from datetime import date
PEPPER = b"secret-loaded-from-vault" # never hardcode in real code
def pseudonym(value: str) -> str:
return hmac.new(PEPPER, value.encode(), hashlib.sha256).hexdigest()[:24]
def age_band(birth: date, today: date = date(2026, 10, 27)) -> str:
age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day))
low = (age // 10) * 10
return f"{low}-{low + 9}"
def region(postcode: str) -> str:
return postcode[:2] + "***" # keep only the coarse area
print(pseudonym("user@example.com"))
print(age_band(date(1991, 4, 12)))
print(region("1000AA"))
# The pepper lives in the vault, never in the repo, the extract, or the ticket.
# Rotate the pepper and the extract is unlinkable to earlier extracts.
3. Measure k-anonymity and group diversity
#!/usr/bin/env python3
"""k-anonymity check - every quasi identifier group must have at least k rows."""
from collections import Counter
# (age_band, region, gender, diagnosis) rows after generalization
ROWS = [
("30-39", "10***", "F", "asthma"),
("30-39", "10***", "F", "diabetes"),
("30-39", "10***", "F", "asthma"),
("40-49", "20***", "M", "asthma"),
("40-49", "20***", "M", "asthma"),
("40-49", "20***", "M", "asthma"),
]
groups = Counter((age, reg, gen) for age, reg, gen, _ in ROWS)
k = min(groups.values())
print(f"k = {k} (smallest group size; aim for k of 5 or higher for external sharing)")
for group, size in sorted(groups.items()):
diagnoses = {d for a, r, g, d in ROWS if (a, r, g) == group}
print(f" {group} size {size} distinct diagnoses {len(diagnoses)}")
if len(diagnoses) == 1:
print(" WARNING - single diagnosis in this group reveals it for every member")
4. Attack your own output before shipping
# Linkage test sketch - join the extract against a known public-style file
# on the quasi identifiers and count how many rows match exactly one person
python3 - <<'EOF'
import csv
from collections import Counter
extract = list(csv.DictReader(open("extract-deidentified.csv")))
public = list(csv.DictReader(open("public-register.csv")))
public_keys = Counter((r["age_band"], r["region"], r["gender"]) for r in public)
unique_matches = sum(
1 for r in extract
if public_keys[(r["age_band"], r["region"], r["gender"])] == 1
)
print(f"Rows matching exactly one public record: {unique_matches} of {len(extract)}")
print("Any nonzero count here must be generalized or suppressed before release.")
EOF
Edge cases
- Longitudinal data defeats one-off checks. The same person across
monthly extracts can be linked by pattern even when each extract
passes, so use consistent generalization and consider fresh
pseudonyms per release window.
- Free text notes, images, and audio can carry identifiers that
column checks never see. Scan or redact unstructured fields before
any release, and treat unreviewed free text as identifying.
- Small populations break anonymity fast. A dataset about a rare
condition, a small town, or a single employer may be unreleasable
in row form no matter the generalization, in which case publish
aggregates only.
- Pseudonymized data is still personal data under GDPR when the key
exists somewhere. Only truly irreversible anonymization, with the
key destroyed and re-identification tested, leaves the scope of
data protection law.
- Differential privacy and de-identification compose well. Adding
calibrated noise to aggregates on top of a de-identified extract
protects against the differencing attacks that row level transforms
alone cannot stop.
Key references
- GDPR Recital 26 - anonymous information versus pseudonymous data
- ISO/IEC 20889 - privacy enhancing data de-identification terminology and classification
- NIST SP 800-188 - de-identification guidance
- Parent skill anonymization-techniques - anonymization foundations
- Sibling skill differential-privacy - noise based protection for aggregates
1---2name: de-identification-techniques3description: "Use when preparing a dataset for sharing, analytics, or testing and direct identifiers must be removed or transformed. Covers direct and quasi identifier discovery, k-anonymity checks, generalization and suppression, pseudonym key handling, and re-identification risk testing. Use when a team asks for production data in a lower environment or when an external partner needs a safe extract."4version: "1.0.0"5domain: privacy6lifecycle: stable7last_verified: "2026-10-27"8parent: anonymization-techniques9requires: [anonymization-techniques]10extends: []11relates: [differential-privacy, data-minimization, dsr-automation]12tools:13 - name: Python14 version: "3.12"15 - name: curl16 version: "8.5"17metadata:18 source: https://skillmd.com/skills/mizazhaider-ceh/de-identification-techniques19---2021De-identification is the work of turning a dataset about identifiable22people into one that cannot reasonably be traced back to them, while23keeping it useful. Removing names alone never achieves that. A24combination of postcode, birth date, and gender can single out most25people, and a "de-identified" extract joined against a public dataset26can quietly re-identify the whole file. This sub-skill covers the27practical pipeline - find every identifier, transform the risky ones,28measure what remains, and attack your own output before anyone else29gets it.3031## Quick Workflow32331. Classify every column - direct identifier, quasi identifier,34 sensitive attribute, or non-identifying.352. Drop direct identifiers outright, unless a keyed pseudonym is36 genuinely needed for linkage, in which case protect the key.373. Generalize quasi identifiers - age bands instead of birth dates,38 regions instead of postcodes - until equivalence classes are big39 enough.404. Suppress or perturb the records that still stand out, and record41 how many rows were affected.425. Measure k-anonymity on the quasi identifiers and check that43 sensitive attributes are diverse within each group.446. Attack your own output - attempt linkage against plausible public45 or partner datasets, and record the success rate.467. Ship with a data sharing agreement that bans re-identification47 attempts, and keep the mapping key separate from the extract.4849## 1. Classify identifiers in a dataset5051```python52#!/usr/bin/env python353"""Identifier classification - direct, quasi, sensitive, or safe."""54import csv55from collections import Counter5657DIRECT = {"name", "email", "phone", "national_id", "customer_id"}58QUASI = {"postcode", "birth_date", "gender", "city", "job_title"}59SENSITIVE = {"diagnosis", "salary", "political_view", "religion"}6061with open("extract.csv", newline="") as fh:62 reader = csv.DictReader(fh)63 for column in reader.fieldnames:64 if column in DIRECT:65 kind = "DIRECT - drop or keyed pseudonym"66 elif column in QUASI:67 kind = "QUASI - generalize and check group sizes"68 elif column in SENSITIVE:69 kind = "SENSITIVE - check diversity within each group"70 else:71 kind = "non-identifying - keep"72 print(f"{column:15s} {kind}")73```7475## 2. Generalize and pseudonymize7677Generalization trades precision for safety, and the trade must be78deliberate per column. Pseudonyms must be keyed and one way - a79sequential fake id, or a hash without a secret, is reversible by80anyone who guesses the scheme.8182```python83#!/usr/bin/env python384"""Generalization plus keyed pseudonyms for a sample extract."""85import hashlib86import hmac87from datetime import date8889PEPPER = b"secret-loaded-from-vault" # never hardcode in real code9091def pseudonym(value: str) -> str:92 return hmac.new(PEPPER, value.encode(), hashlib.sha256).hexdigest()[:24]9394def age_band(birth: date, today: date = date(2026, 10, 27)) -> str:95 age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day))96 low = (age // 10) * 1097 return f"{low}-{low + 9}"9899def region(postcode: str) -> str:100 return postcode[:2] + "***" # keep only the coarse area101102print(pseudonym("user@example.com"))103print(age_band(date(1991, 4, 12)))104print(region("1000AA"))105# The pepper lives in the vault, never in the repo, the extract, or the ticket.106# Rotate the pepper and the extract is unlinkable to earlier extracts.107```108109## 3. Measure k-anonymity and group diversity110111```python112#!/usr/bin/env python3113"""k-anonymity check - every quasi identifier group must have at least k rows."""114from collections import Counter115116# (age_band, region, gender, diagnosis) rows after generalization117ROWS = [118 ("30-39", "10***", "F", "asthma"),119 ("30-39", "10***", "F", "diabetes"),120 ("30-39", "10***", "F", "asthma"),121 ("40-49", "20***", "M", "asthma"),122 ("40-49", "20***", "M", "asthma"),123 ("40-49", "20***", "M", "asthma"),124]125groups = Counter((age, reg, gen) for age, reg, gen, _ in ROWS)126k = min(groups.values())127print(f"k = {k} (smallest group size; aim for k of 5 or higher for external sharing)")128for group, size in sorted(groups.items()):129 diagnoses = {d for a, r, g, d in ROWS if (a, r, g) == group}130 print(f" {group} size {size} distinct diagnoses {len(diagnoses)}")131 if len(diagnoses) == 1:132 print(" WARNING - single diagnosis in this group reveals it for every member")133```134135## 4. Attack your own output before shipping136137```bash138# Linkage test sketch - join the extract against a known public-style file139# on the quasi identifiers and count how many rows match exactly one person140python3 - <<'EOF'141import csv142from collections import Counter143extract = list(csv.DictReader(open("extract-deidentified.csv")))144public = list(csv.DictReader(open("public-register.csv")))145public_keys = Counter((r["age_band"], r["region"], r["gender"]) for r in public)146unique_matches = sum(147 1 for r in extract148 if public_keys[(r["age_band"], r["region"], r["gender"])] == 1149)150print(f"Rows matching exactly one public record: {unique_matches} of {len(extract)}")151print("Any nonzero count here must be generalized or suppressed before release.")152EOF153```154155## Edge cases156157- Longitudinal data defeats one-off checks. The same person across158 monthly extracts can be linked by pattern even when each extract159 passes, so use consistent generalization and consider fresh160 pseudonyms per release window.161- Free text notes, images, and audio can carry identifiers that162 column checks never see. Scan or redact unstructured fields before163 any release, and treat unreviewed free text as identifying.164- Small populations break anonymity fast. A dataset about a rare165 condition, a small town, or a single employer may be unreleasable166 in row form no matter the generalization, in which case publish167 aggregates only.168- Pseudonymized data is still personal data under GDPR when the key169 exists somewhere. Only truly irreversible anonymization, with the170 key destroyed and re-identification tested, leaves the scope of171 data protection law.172- Differential privacy and de-identification compose well. Adding173 calibrated noise to aggregates on top of a de-identified extract174 protects against the differencing attacks that row level transforms175 alone cannot stop.176177## Key references178179- GDPR Recital 26 - anonymous information versus pseudonymous data180- ISO/IEC 20889 - privacy enhancing data de-identification terminology and classification181- NIST SP 800-188 - de-identification guidance182- Parent skill anonymization-techniques - anonymization foundations183- Sibling skill differential-privacy - noise based protection for aggregates