Learn

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.

A masking policy for a payment cards table, with the card number column set to Same format and the identifier type Card number
The card number column: Same format, with the identifier type Card number.
IdentifierWhat the masked number keeps
Card numberThe length, the layout, the first digit and the card check
IBANThe country code and a valid check
United States: Social Security numberThe layout, and never a range that is not issued
Canada: Social Insurance NumberThe layout and a valid check digit
United Kingdom: NHS numberThe layout and a valid check digit
Australia: TFN, ABN, ACN and Medicare numberThe layout and a valid check digit
New Zealand: IRD numberThe layout and a valid check digit
Any other identifierThe 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.

A masking policy for a tax returns table, with a business number column set to Same format and its identifier type
Washery found valid check digits in this column and proposed Same format with the matching identifier type.

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.

Related

Mask your first database today

Connect your account, review what Washery will mask, and pay only when you create the masked copy.

Want to talk it through first? Book a 20-minute demo.

Mask your first database