How to mask card numbers and government ID numbers so they stay valid
Replace each number with a different number that has the same layout and a valid check digit. A masked card number still passes the card check, and a masked tax ID or national ID number still passes its check. The application accepts them, and nobody can work back to the original.
Why not replace the digits with random ones?
Most of these numbers have a check digit. The last digit of a card number is calculated from the other digits, and an application that validates card numbers rejects nine in ten random ones. Many tax IDs, national ID numbers and bank account numbers have a check digit too.
A masked number that fails its check is rejected by the same code your developers are trying to test.
What do the rules say about card numbers in test?
PCI DSS version 4.0.1, requirement 6.5.5, says live card numbers are not used in pre-production environments. The exception is a pre-production environment that is part of the cardholder data environment and protected to the same standard.
A dev or test database therefore needs card numbers that are not the real ones, and that still pass the card check.
What does a masked identifier have to keep?
- The layout. The same length, with spaces and dashes where they were.
- The check digit. A number that was valid is still valid.
- Uniqueness. Two different numbers become two different masked numbers.
- Relationships. The same number becomes the same masked number in every table, so joins still match.
It must also be one-way, so nobody can work back to the original number.
How Washery does it
Washery proposes the Same format method for identifiers, with the identifier type it found. You approve the policy before anything is masked.

| Identifier | What the masked number keeps |
|---|---|
| Card number | The length, the layout, the first digit and the card check |
| IBAN | The country code and a valid check |
| United States: Social Security number | The layout, and never a range that is not issued |
| Canada: Social Insurance Number | The layout and a valid check digit |
| United Kingdom: NHS number | The layout and a valid check digit |
| Australia: TFN, ABN, ACN and Medicare number | The layout and a valid check digit |
| New Zealand: IRD number | The layout and a valid check digit |
| Any other identifier | The layout: digits stay digits and letters stay letters |
A number that was valid stays valid, and a number that was not valid stays not valid, so tests for bad input still work.

Each run uses a new key that is never kept, so a masked number cannot be turned back into the original. For an identifier only you have, such as a member number, create a custom mask.
When is this not the right approach?
- You need to take a test payment. Use the test card numbers your payment provider publishes.
- The column holds a secret, such as a card security code or a PIN. Clear it.
Source, checked 2 December 2026: PCI DSS version 4.0.1, requirement 6.5.5, from the PCI Security Standards Council.