National Insurance Number Validator

A National Insurance number validator checks the two-letter prefix, six digits and suffix letter of a NINO against the allocation rules HMRC publishes in its National Insurance Manual.

A National Insurance number looks like AB 12 34 56 C: two letters, six digits and a suffix. The letters are the part most validators get wrong. Neither prefix letter can be D, F, I, Q, U or V, the second letter is never O, and the prefixes BG, GB, NK, KN, TN, NT and ZZ are not allocated. The suffix is A, B, C or D. This tool applies every one of those rules, flags HMRC’s administrative prefixes and the pre-2001 TN temporary format, and generates numbers that pass, for payroll, HR and onboarding test data.

Use cases

  • Payroll and HR form validation: Reject typos and impossible prefixes at the form, with a message that says which rule failed.
  • Test data for onboarding flows: Format-valid numbers for fixtures and demos, without using a real employee’s number.
  • Checking a regex: Paste the edge cases: a banned letter, an unallocated prefix, a missing suffix, and see what a correct validator does with each.

Frequently asked questions

Why is QQ 12 34 56 C invalid when HMRC uses it as an example?

Because Q is never used in a prefix, HMRC chose it for examples precisely so the example can never be a real number. A validator that accepts it is too loose.

Is the suffix letter required?

HMRC issues every number with a suffix, but some systems and documents omit it. The tool accepts both; decide for your own form whether to require it.

Can a generated number belong to a real person?

In principle yes, since HMRC reserves no test range. The number alone identifies nobody, but keep generated numbers out of anything that reaches HMRC or DWP systems.

The National Insurance number format

What the letters mean, which ones never appear, and how to validate the rest · 550 words

1. Two letters, six digits, one letter

A National Insurance number is written AB 12 34 56 C: a two-letter prefix, six digits and a suffix letter. HMRC's National Insurance Manual, at NIM39110, sets out the rules. Neither prefix letter may be D, F, I, Q, U or V, and the second letter may not be O. The prefixes BG, GB, NK, KN, TN, NT and ZZ are not allocated. The suffix is A, B, C or D.

The digits carry no check digit and no encoded meaning, so a validator can only check the letters and the length. That is still worth doing: a form that accepts any two letters passes numbers that cannot exist, and a number with a Q in the prefix is a typo or a test value every time.

2. Prefixes with a special meaning

Until April 2001 employers could issue a temporary number in the form TN, the date of birth as six digits, and M or F. Those numbers are no longer valid and no longer accepted by payroll software, which is why TN is on the unallocated list. HMRC and DWP also use administrative references with prefixes such as OO, CR, FY, MW, NC, PP, PY and PZ for tax and benefit purposes rather than for people. A payroll system should accept them with care and a customer onboarding form should probably not.

HMRC's own example number, QQ 12 34 56 C, fails the rules on purpose: Q never appears in a prefix, so the example can never be anyone's real number. A validator that accepts QQ is too loose.

3. A validator

Normalise first: upper-case the input and remove spaces and hyphens, because people type the number as it appears on their letter, with spaces, or as a single run of characters. Then check the shape, then the letters.

function isValidNino(input) {
  const v = input.toUpperCase().replace(/[\s-]/g, '');
  if (!/^[A-Z]{2}\d{6}[A-D]$/.test(v)) return false;
  const banned = /[DFIQUV]/;
  if (banned.test(v[0]) || banned.test(v[1]) || v[1] === 'O') return false;
  return !['BG', 'GB', 'NK', 'KN', 'TN', 'NT', 'ZZ'].includes(v.slice(0, 2));
}

4. National Insurance numbers in test data

HMRC reserves no range for testing, so there is no equivalent of the NHS 999 range. A generated number that follows the rules could in principle be someone's, although a number on its own identifies nobody and the odds are long. Keep generated numbers in test environments, keep them out of anything that reaches HMRC or DWP systems, and never use a real employee's number in a fixture. HMRC's developer sandbox documents the specific test numbers its own APIs expect; use those when testing an integration with HMRC.

Pair a generated number with a generated name, date of birth and address rather than real ones. The point of synthetic test data is that no row belongs to a real person, and a real name next to a fictional number undoes that.

More questions

Does the suffix letter mean anything?

Historically it indicated which quarter of the year a contribution card was due back. It has no administrative meaning today but is still issued with every number, and most validators require it.

Can a National Insurance number start with any letter?

No. The first letter is never D, F, I, Q, U or V. Everything else is possible, subject to the second-letter rule and the unallocated prefixes.

Is a National Insurance number proof of identity?

No. It is a reference for contributions and benefits. Identity checks need documents or an electronic identity verification; see the guide to testing KYC flows for how to test those.

Related tools