NHS Number Validator

An NHS number validator recalculates the modulus 11 check digit from the first nine digits of a ten-digit NHS number and reports whether the tenth digit matches.

Every NHS number is ten digits, written 943 476 5919, and the last digit is a check digit. The first nine digits are multiplied by 10 down to 2, the products are added, the remainder after dividing by 11 is subtracted from 11, and the result must equal the final digit (11 counts as 0, and 10 means no valid number exists). The tool runs that calculation, tells you which issuing range the number sits in, and generates numbers from 999 000 0000 to 999 999 9999, which NHS England reserves for test and development systems and never issues to a patient.

Use cases

  • Health and care software test data: Numbers that pass validation and are guaranteed fictional, for patient records, integration tests and demos.
  • Validating input in clinical and admin systems: Catch transposed and mistyped digits at the point of entry, before a lookup against the Personal Demographics Service.
  • Learning the algorithm: See the weights, the modulus and the two special cases, with a worked example you can check by hand.

Frequently asked questions

Are the generated numbers real NHS numbers?

No. They come from the 999 range reserved for test systems. They pass the check digit, so validators accept them, and they can never be issued to a patient.

Does a valid check digit mean the number is issued?

No. One number in roughly every eleven passes by chance. Only the Personal Demographics Service confirms that a number is issued and to whom.

Is a Scottish CHI number an NHS number?

It is the same ten-digit format with the same check digit, issued by NHS Scotland. CHI numbers encode the date of birth in the first six digits and fall in the 010 to 319 range.

The NHS number and its check digit

Ten digits, a modulus 11 check, and the ranges that say who issued it · 550 words

1. Ten digits in a 3-3-4 layout

An NHS number is ten digits, written 943 476 5919, and the tenth digit is a check digit calculated from the other nine. The format is shared by NHS England and Wales, NHS Scotland (where it is called the Community Health Index or CHI number) and Northern Ireland (the Health and Care number), and the leading digits say which system issued it. Numbers from 010 to 319 are Scottish CHI numbers, which encode the date of birth in the first six digits; 320 to 399 are Northern Irish; 400 to 499 and 600 to 799 are England, Wales and the Isle of Man.

2. The modulus 11 calculation

Multiply the first nine digits by 10, 9, 8, 7, 6, 5, 4, 3 and 2 in turn and add the products. Divide by 11 and take the remainder. Subtract the remainder from 11. 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, and the issuing system skips them. Otherwise the result must equal the tenth digit.

For 943 476 591: 90 + 36 + 24 + 28 + 42 + 30 + 20 + 27 + 2 = 299; 299 mod 11 = 2; 11 − 2 = 9, so the number is 943 476 5919. Transposing two adjacent digits, or mistyping one, changes the result, which is what the check digit is for.

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])

3. Test numbers

NHS England reserves 999 000 0000 to 999 999 9999 for test and development systems. Numbers in that range pass the check digit, so validators accept them, and they are never issued to a patient, so a test record can never be confused with a real one. The wider 900 to 999 range is unallocated and used by development systems, and 500 to 599 is used for the NHS Care Records Service's own internal testing.

Use the 999 range for every synthetic patient record. It is the one identifier in UK test data where the issuing body has done the work of guaranteeing fictional values, and there is no reason to generate anything else.

4. What a valid number does not tell you

About one ten-digit string in eleven passes the check by chance, so a passing number is not evidence that it is issued. The Personal Demographics Service is the source of truth for whether a number exists and whose it is, and clinical systems trace numbers against it rather than trusting the check digit. In software terms: validate the check digit at the form, to catch typing errors instantly, and verify against PDS before the number is used for anything that matters.

More questions

Is the NHS number the same across the UK?

The ten-digit format and the check digit are the same. Scotland issues CHI numbers and Northern Ireland issues Health and Care numbers from their own ranges, and systems that serve all four nations need to accept all of them.

Why do some nine-digit prefixes have no valid number?

When the calculation gives 10 there is no single digit that satisfies the check, so those nine-digit prefixes are skipped. About one in eleven prefixes falls in that gap.

Can I use the generated numbers in a live NHS system?

They are intended for test and development systems. Whether a particular live environment accepts the 999 range is a question for that system’s owner.

Related tools