The NHS Number Format and Check Digit Explained
Reference · November 2026 · 9 min read
The ten-digit NHS number, its modulus 11 check digit with a worked example and code in three languages, the ranges for England, Scotland and Northern Ireland, and the 999 range reserved for test data.
Every patient registered with the NHS in England, Wales and the Isle of Man has a ten-digit NHS number, and Scotland and Northern Ireland issue numbers in the same format under different names. The last digit is a check digit, calculated by a published algorithm, and NHS England reserves a whole range of numbers for test systems. Between them, those two facts make the NHS number the best-behaved identifier in UK test data. This guide explains the format, the check digit, the ranges, and how to generate safe test numbers.
The format
An NHS number is ten digits, written in a 3-3-4 layout:
943 476 5919
└─────────┘└┘
9 digits check digit
The first nine digits identify the record. The tenth is calculated from them, so a single mistyped digit, or two adjacent digits swapped, produces a number that fails the check. That is the point: NHS numbers are read over the phone, typed from paper and scanned from wristbands, and the check digit catches most transcription errors before they reach a patient record.
The check digit algorithm
The calculation is modulus 11, as published in the NHS Data Dictionary:
1. Multiply each of the first nine digits by a weight. The first digit is multiplied by 10, the second by 9, and so on down to the ninth, which is multiplied by 2. 2. Add the nine products together. 3. Divide the total by 11 and take the remainder. 4. Subtract the remainder from 11. 5. If the result is 11, the check digit is 0. If the result is 10, the number is invalid: no valid NHS number exists with those nine leading digits. Otherwise the result is the check digit, and it must equal the tenth digit.
Working through 943 476 591:
Total 299. 299 ÷ 11 is 27 remainder 2. 11 − 2 = 9. So the full number is 943 476 5919, and 943 476 5918 would be rejected.
The "result of 10" case means that roughly one nine-digit prefix in eleven has no valid tenth digit at all, and the issuing systems simply skip those. A generator that does not handle this produces numbers that look right and fail validation.
Code
function nhsNumberValid(input) {
const digits = input.replace(/\s/g, '');
if (!/^\d{10}$/.test(digits)) return false;
const total = digits
.slice(0, 9)
.split('')
.reduce((sum, d, i) => sum + Number(d) * (10 - i), 0);
let check = 11 - (total % 11);
if (check === 11) check = 0;
return check !== 10 && check === Number(digits[9]);
}
nhsNumberValid('943 476 5919'); // true
nhsNumberValid('943 476 5918'); // false
def nhs_number_valid(value: str) -> bool:
digits = value.replace(" ", "")
if len(digits) != 10 or not digits.isdigit():
return False
total = sum(int(d) * w for d, w in zip(digits[:9], range(10, 1, -1)))
check = 11 - (total % 11)
if check == 11:
check = 0
return check != 10 and check == int(digits[9])
And in SQL, for checking a column in place (PostgreSQL syntax):
SELECT nhs_number,
(11 - (
10*substr(n,1,1)::int + 9*substr(n,2,1)::int + 8*substr(n,3,1)::int +
7*substr(n,4,1)::int + 6*substr(n,5,1)::int + 5*substr(n,6,1)::int +
4*substr(n,7,1)::int + 3*substr(n,8,1)::int + 2*substr(n,9,1)::int
) % 11) % 11 = substr(n,10,1)::int AS check_ok
FROM (SELECT nhs_number, replace(nhs_number, ' ', '') AS n FROM patients) t
WHERE n ~ '^\d{10}#39;;
The trailing % 11 turns a result of 11 into 0; a result of 10 can never equal a single digit, so it fails naturally.
Which range a number comes from
The leading digits say which system issued the number:
A CHI number is worth a note. It is the same ten digits with the same check digit, but the first six digits are the patient's date of birth as DDMMYY, and the ninth digit is odd for men and even for women. A system that serves Scotland needs to accept CHI numbers, and a system that generates test data for Scotland should produce numbers whose first six digits are a plausible date.
The test range
NHS England reserves 999 000 0000 to 999 999 9999 for test purposes. Numbers in that range pass the check digit, so every validator accepts them, and they are never issued to a patient, so a test record can never be mistaken for a real one, even if a test database leaks or a screenshot ends up in a slide deck.
This is unusual. Most UK identifiers have no reserved test range: National Insurance numbers and company numbers could in principle coincide with real ones however you generate them. For NHS numbers the issuing body has done the work, and there is no reason to generate anything outside the 999 range for test data.
Generating one is the check digit calculation in reverse: pick 999 and six random digits, compute the check digit, and discard the candidate if the result is 10.
function testNhsNumber() {
for (;;) {
const body = '999' + String(Math.floor(Math.random() * 1e6)).padStart(6, '0');
const total = body.split('').reduce((sum, d, i) => sum + Number(d) * (10 - i), 0);
let check = 11 - (total % 11);
if (check === 11) check = 0;
if (check !== 10) return body + check;
}
}
The NHS number validator on this site runs the check, reports the range, and generates 999-range numbers in bulk.
What a valid number does not tell you
A passing check digit says the number was transcribed correctly. It does not say the number is issued, or to whom. About one random ten-digit string in eleven passes by chance. The Personal Demographics Service is the national source of truth for NHS numbers in England and Wales, and clinical systems trace a number against it (matching name, date of birth and postcode) before trusting it. In software terms: validate the check digit at the point of entry to catch typing errors instantly, and verify against PDS, or the equivalent national service, before the number is used for anything clinical.
NHS numbers in test data
Three rules cover almost every case:
1. Use the 999 range for every synthetic patient. It is free, safe and accepted by validators. 2. Never use a real NHS number in a test environment, including your own. Health data is special category data under UK GDPR, the fines are the highest available, and the reputational cost of a leaked patient identifier is worse than the fine. The general argument is in using real customer data in test environments. 3. Generate the rest of the record too. A 999-range number next to a real name and address is still a real person. The test data generator produces complete fictional personas with UK addresses, and the name generator covers names on their own.
Health and care software has to pass the same KYC-style identity checks as other regulated sectors, and testing identity verification flows covers how to do that without real identities.
More guides
- How to Check if a UK Address Is Real (and What “Valid” Actually Means)
- UK Bank Account Numbers: How Many Digits, How to Read One, and How to Check It
- The National Insurance Number Format Explained, with a Validator
- UK Company Registration Numbers: Format and Prefixes Explained
- What Is a Post Town? How to Find Yours, and Why It Isn’t Always Your Town
- The UK Driving Licence Number Format Explained
- How Address Verification Software Works: PAF, UPRNs, Match Levels and What to Ask a Vendor
- Data Masking, Anonymisation and Pseudonymisation Under UK GDPR: What Each One Actually Means
- Validating UK Phone Numbers: Formats, Ofcom Ranges and the Mistakes Every Regex Makes
- Mocking a UK Address Lookup API in Your Tests
- Testing KYC and Identity Verification Flows Without Real Identities
- Test Data Management: Production Copies, Masked Data and Synthetic Data
- UK Sort Codes, Account Numbers, IBANs and SWIFT Codes for Test Data
- The UK VAT Number Format Explained, with a Check-Digit Validator
- The UK Postcode Format Explained: Areas, Districts, Sectors and Units
- Royal Mail Address Formatting: How to Lay Out a UK Address Correctly
- How UK Address Generators Work — and How to Tell a Good One
- Using Real Customer Data in Test Environments: The UK GDPR Problem
- Why Your Address Form Rejects Perfectly Valid UK Addresses
- The UK Telephone Numbering Plan, and the Numbers Reserved for Fiction
- Validating UK Postcodes in JavaScript, Python and SQL
- Where UK Address Data Comes From: PAF, ONSPD, OS Open Names and AddressBase
- Why Faker's UK Postcodes Fail Validation