Building an Invalid NHS Number Generator.doc

Building an Invalid NHS Number Generator

5 August 2026 Harry Chapman

I built a browser tool that creates ten-digit NHS numbers guaranteed to fail the official Modulus 11 checksum, then shows the maths behind why each one is invalid.

When you are testing a clinical form or building a demo environment, you eventually reach a box that asks for a ten-digit NHS number.

At this point, a tester has three bad options:

  1. Type 123 456 7890 and watch the form reject it immediately because the field validates the official NHS checksum.
  2. Mash the number pad at random until the red error text goes away.
  3. Copy a real number from somewhere they shouldn’t.

Option 2 sounds harmless until you realise what passing the checksum means. There are a billion possible nine-digit prefixes (10⁹), and roughly 70 million people in the UK. If you randomly generate a ten-digit number that passes the NHS Modulus 11 check, you have an uncomfortably real chance of accidentally inventing an actual person’s medical identifier inside a test database or a recorded screen share.

I built the Invalid NHS Number Generator to give QA and demo work a fourth option: ten-digit numbers formatted as 000 000 0000 that are mathematically guaranteed never to belong to a real patient.

How the tenth digit snitches on the first nine

An NHS number is nine source digits (d₁ through d₉) followed by a single check digit (d₁₀), validated using Modulus 11 arithmetic:

  1. Multiply each of the first nine digits by a descending weight from 10 down to 2, and sum them: S = (d₁ × 10) + (d₂ × 9) + ... + (d₉ × 2)
  2. Divide the sum S by 11 and find the remainder R = S mod 11.
  3. Subtract the remainder from 11 to get the check value C = 11 - R (if C = 11, the check digit is 0).

Here is a fun quirk of the specification: what happens if the remainder R is 1, making C = 10? An NHS number only has one slot for the check digit, so you cannot write 10 in the tenth position. Any nine-digit prefix that produces C = 10 is simply illegal and is never issued by the Personal Demographics Service.

Failing on purpose

To make a number that is safe by construction, the generator rolls a random nine-digit prefix and runs the exact Modulus 11 calculation above to find out what the real tenth digit would be.

Then it deliberately refuses to use it.

It picks a different digit for position ten (or, if the prefix landed on the forbidden check value of 10, picks any digit at all, since every possible tenth digit will fail validation). The UI prints the formatted number alongside a one-line breakdown showing the calculated check digit versus the sabotaged one.

Showing that working solves two problems at once. If an information governance reviewer looks at a screenshot of a training deck, you can prove in five seconds that the identifier on screen cannot pass checksum validation. And if a developer is testing form validation, they can tell immediately that their code rejected the input because of the Modulus 11 check rather than a stray space or length error.

The whole thing lives in a single static HTML file with zero network requests, zero analytics and no backend. Nothing you generate leaves the browser tab.

Use the generator or inspect the implementation.

Page 1 535 words 3 min Work