Skip to content

Identifier detector

NHS number: format, validation and detection

Updated United Kingdomnational ID numberDetector key gb_nhs_number

Short answer

An NHS number has 10 digits; the last is a modulus 11 check digit calculated with weights 10 down to 2 over the first nine digits. If the calculation gives 10, the number is never issued.

What it is

The NHS number identifies a patient in the UK health services. Maskflare has two detectors with the same validator: gb_nhs_number in the United Kingdom pack and nhs_number in the Healthcare (PHI) pack. The United Kingdom pack also has an unformatted sibling for runs with no separators.

In Maskflare this is the detector gb_nhs_number, labelled "United Kingdom - NHS number", category national id number, in the United Kingdom pack.

Format and layout

  • 10 digits, printed 3-3-4 with spaces or hyphens, such as 943 476 5919. A separate detector handles unseparated runs.
  • All ten digits cannot be identical.
  • The tenth digit is the check digit.

How the check works

Multiply the first nine digits by 10, 9, 8, 7, 6, 5, 4, 3 and 2 and add the products. Divide the total by 11 and take the remainder. The check digit is 11 minus the remainder; 11 is read as 0. A result of 10 means the number cannot be valid.

Worked example

  1. Digits 9 4 3 4 7 6 5 9 1 with weights 10 9 8 7 6 5 4 3 2 give 90, 36, 24, 28, 42, 30, 20, 27, 2.
  2. The total is 299, and 299 divided by 11 leaves 2.
  3. 11 minus 2 is 9, the last digit of the example.

Valid and invalid examples

Synthetic values. Each was run through Maskflare's own validator and pattern when this page was generated.
ExampleResultWhy
943 476 5919ValidMatches the layout and passes the validator.
943 476 5910InvalidThe invalid example changes one character, the last character: 9 becomes 0.

In running text the valid example reads, for instance, patient 943 476 5919. The invalid one is left alone: a value that fails the validator is treated as an ordinary string.

Regex and validation caveats

  • The unseparated 10-digit form belongs to a sibling detector that needs one of its keywords (five in the catalogue) before the number. The 3-3-4 form needs none.
  • About one in eleven random 10-digit numbers passes the modulus 11 test, so ten-digit phone numbers and IDs can pass the check alone. That is why unseparated runs need a keyword.
  • The separated 3-3-4 shape is distinctive enough to be matched on its own.

How to detect it in LLM traffic

NHS 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 NHS number candidates.
  3. Run the check from the section above. A failing check is almost always a typo or a made-up value; a passing one removes most look-alikes.
  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

How is the NHS number check digit calculated?

Weight the first nine digits 10 to 2, sum them, take the remainder after dividing by 11, subtract it from 11, and treat 11 as 0. If the answer is 10 the number is invalid.

Why are there two NHS number detectors?

One belongs to the United Kingdom pack and one to the Healthcare (PHI) pack, so the number is caught whether an organisation enables UK identifiers, health identifiers, or both.

Is the NHS 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 NHS number prove the person exists?

No. A check digit shows the value is well formed. Many valid-looking numbers have never been issued, and Maskflare masks them all the same.

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.