# Data Masking

> Showing stars in place of a private value. The real one is still kept.

**Field:** Data Engineering  
**Category:** Data Privacy  
**Also known as:** Dynamic Data Masking, Masking Policy, Data Redaction

## Think of it like

It is like a sticker on a photo. The photo is still there, but the face is hidden.

## Definition

Data masking hides private values by showing a covered version. An email might show only its first letter. A card number might show only its last four digits. With dynamic masking, the real data stays in the table. A rule checks who is asking and shows the real value only to some roles. Static masking makes a covered copy, such as for a test system.

## Example

Analysts at a bank can count customers by city, but card numbers show only the last four digits. The fraud team sees them in full.

## Example code

```sql
CREATE MASKING POLICY email_mask AS (val STRING)
  RETURNS STRING ->
  CASE WHEN CURRENT_ROLE() IN ('SUPPORT') THEN val
       ELSE '*****' END;

ALTER TABLE customers MODIFY COLUMN email
  SET MASKING POLICY email_mask;
```

A Snowflake masking rule. Support staff see the real email, and everyone else sees stars.

## Why it matters

Many people can use one table safely. No one has to make a copy for each role.

## Common mistake

Masking in the dashboard only. Anyone who queries the table directly still sees the real values.

## Three principles

- **Covered values.** Stars or part of the value.
- **By role.** Allowed roles see the real value.
- **Dynamic or static.** On read, or in a covered copy.

## Related terms

- [Personally Identifiable Information (PII)](https://learn.benibix.com/term/data/personally-identifiable-information)
- [Pseudonymization](https://learn.benibix.com/term/data/pseudonymization)
- [Data Anonymization](https://learn.benibix.com/term/data/data-anonymization)
- [Role-Based Access Control (RBAC)](https://learn.benibix.com/term/development/role-based-access-control)
- [Column-Level Security](https://learn.benibix.com/term/data/column-level-security)
- [Data Classification](https://learn.benibix.com/term/data/data-classification)

## Told apart from

- [Column-Level Security vs Data Masking](https://learn.benibix.com/compare/column-level-security-vs-data-masking): People think closing a column and masking it do the same job. A closed column cannot be read at all. A query that asks for it fails with an error. A masked column can be read, but the value comes back hidden, like a card number shown as stars. Closing suits fields a role never needs. Masking suits fields a role needs to see exist.

![One customer row shown four ways. Original: Emma Brown, emma@example.com, born 1990-04-12. Masked: E**** B****, e***@example.com. Pseudonymized: customer token 7f3a9c, same token every time. Anonymized: an age band of 30 to 39 in a count of 412 people, with no way back to Emma.](https://learn.benibix.com/diagrams/data-masking.svg)

---

Source: https://learn.benibix.com/term/data/data-masking
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
