Skip to content

Identifier detector

UK National Insurance number: format, validation and detection

Updated United Kingdomsocial security numberDetector key gb_nino

Short answer

A UK National Insurance number is two letters, six digits and a suffix letter A to D. It has no check digit, so detection rests on the letter rules: certain prefix letters and pairs are never allocated.

What it is

The NI number identifies people for UK tax and social security. Maskflare keeps it in the United Kingdom pack as a social security number, and the UK GDPR compliance profile includes the pack.

In Maskflare this is the detector gb_nino, labelled "United Kingdom - National Insurance number", category social security number, in the United Kingdom pack.

Format and layout

  • Two letters, six digits, one letter from A to D: AB 123456 C, often printed in pairs as AB 12 34 56 C.
  • The first letter cannot be D, F, I, Q, U or V.
  • The second letter cannot be D, F, I, O, Q, U or V.
  • The prefixes BG, GB, KN, NK, NT, TN and ZZ are never allocated and are rejected.

How the check works

There is no checksum. The validator, as its source says, applies the structure and letter rules only. That makes it a weaker test than the checksum-based detectors: it accepts any number with an allowed prefix and a suffix of A to D.

Valid and invalid examples

Synthetic values. Each was run through Maskflare's own validator and pattern when this page was generated.
ExampleResultWhy
AB 12 34 56 CValidMatches the layout and passes the validator.
GB 12 34 56 CInvalidThe invalid example changes one character, character 1 of 13: A becomes G.

In running text the valid example reads, for instance, NI number AB 12 34 56 C. The invalid one is left alone: a value that fails the validator is treated as an ordinary string.

Regex and validation caveats

  • Because there is no check digit, a code like an internal reference with two letters, six digits and a final A to D can look like an NI number. The prefix rules remove many but not all of these.
  • The detector has no context words and matches the shape wherever it appears, with or without spaces.
  • The invalid example on this page changes the prefix to GB, one of the pairs the validator rejects.

How to detect it in LLM traffic

UK National Insurance number values reach an LLM inside ordinary work rather than as standalone data: a pasted block of HR or payroll rows, a customer-support thread, an onboarding or identity-check form, a spreadsheet someone wants summarised, or an email they want rewritten. The model needs none of the digits for any of those jobs, so the safest place to remove them is before the request leaves the company.

Maskflare reads the whole request body, including the system prompt, earlier messages and tool arguments, so a number buried in the fourth message of a long chat is found as readily as one in the latest message. Each match is replaced with a token such as mf_mask_d7e0 before the request goes out, and with response restoration turned on the real value is put back into the answer for the person who is allowed to see it.

If you build the detection yourself

  1. Strip spaces, dots and hyphens before running any arithmetic, but remember where they were so the original text can be replaced exactly.
  2. Match the shape with a pattern anchored on word boundaries, so that a long digit string is not read as several shorter UK National Insurance number candidates.
  3. Apply the layout rules from the section above. This identifier has no check digit to recompute, so expect more look-alikes than with a checksum-based format.
  4. Replace the value before the text is sent anywhere, and keep a mapping if the answer has to be restored afterwards.

How Maskflare handles it

  • Protect now, Finance - Protect now, Healthcare and Developer: mask (a reversible token) when United Kingdom is a primary country.
  • Monitor first: alert (counted, forwarded unchanged) when United Kingdom is a primary country.

The available actions are mask (reversible token), redact, partial, hash, format-preserving encryption, generalize, alert and block. Masked values are kept encrypted for 30 days so that answers can be restored, then they expire; prompts and responses are not logged. The full list of detectors is in the detector reference.

Compliance profiles that include it

One compliance profile includes the United Kingdom pack, and applying it turns this detector on: UK GDPR. A profile is a floor: it never turns anything off or weakens a rule that is already stricter.

Frequently asked questions

Does an NI number have a check digit?

Maskflare's validator does not use one. It checks the letter rules and the A to D suffix.

Which NI prefixes does Maskflare ignore?

BG, GB, KN, NK, NT, TN and ZZ, plus any prefix that starts with D, F, I, Q, U or V or whose second letter is D, F, I, O, Q, U or V.

Is the UK National Insurance number detector on by default?

It depends on the organisation's primary countries. It is part of the United Kingdom pack, which the default Protect now template turns on with the action mask when United Kingdom is a primary country.

Does a valid UK National Insurance number prove the person exists?

No. This identifier is validated on its layout alone, so a passing value is only well formed, not known to be real.

Rules on this page describe what Maskflare's detectors and validators check. They are read from the detection catalogue and are not the specification of the body that issues the identifier. Examples are synthetic.

Related pages

See it on your own data

Try Maskflare free.
Bring your hardest prompts.

28-day free trial or 10,000 requests, whichever comes first. Point one app at the gateway or enroll a few laptops,
and watch what gets masked. Or talk to us first.