The National Insurance Number Format Explained, with a Validator
Reference · November 2026 · 8 min read
HMRC's exact rules for a NINO: the letters that never appear, the unallocated prefixes, the A to D suffix, temporary and administrative numbers, a validator in JavaScript and Python, and how to handle NINOs in test data.
A National Insurance number is the reference HMRC and the Department for Work and Pensions use to record a person's contributions and benefits. It looks simple, AB 12 34 56 C, but the rules about which letters can appear are strict and public, and most validators get them wrong. This guide sets out the format exactly as HMRC documents it, with a validator you can paste, and covers what the number does and does not prove.
The format
A National Insurance number, or NINO, is nine characters: two letters, six digits and one letter, written in pairs with the suffix on its own:
AB 12 34 56 C
└┘ └──────┘ └┘
prefix digits suffix
HMRC's rules, from its National Insurance Manual at NIM39110:
- Neither prefix letter is D, F, I, Q, U or V.
- The second prefix letter is never O.
- The prefixes BG, GB, NK, KN, TN, NT and ZZ are not allocated.
- The suffix is A, B, C or D.
The six digits are a serial number. They carry no check digit and encode nothing, which means a validator can only check the letters and the length. Everything else about whether a number is genuine lives in HMRC's systems.
What the letters mean
The prefix letters were originally allocated in blocks to the offices that issued numbers, which is why some combinations exist and others do not. The excluded letters avoid confusion with digits (I with 1, O with 0), with each other (U and V), and with existing internal references (D, F and Q were used for other purposes). None of that is needed to validate a number; it just explains why the rules look arbitrary.
The suffix letter once indicated the quarter of the year in which a paper contribution card had to be returned: A for March, B for June, C for September, D for December. The cards are long gone, but the suffix is still issued with every number and most systems require it.
Prefixes with special status
Temporary numbers. Until April 2001, an employer who did not have an employee's NINO could use a temporary number in the form TN, the date of birth as six digits, and M or F: TN 31 12 80 M. These were never real NINOs, could not be used to trace contributions, and were withdrawn. Payroll software rejects them, which is why TN is on the unallocated list. If a legacy database still holds TN numbers, they are placeholders for a NINO that was never collected.
Administrative references. HMRC and DWP use references with prefixes such as OO, CR, FY, MW, NC, PP, PY and PZ for tax and benefit purposes. They follow the NINO shape but are not numbers issued to a person. A payroll or benefits system may need to accept some of them; a customer-facing form almost certainly should not.
HMRC's example. HMRC's own documents use QQ 12 34 56 C as the example number. Q is never used in a prefix, so the example can never belong to anyone. It is also the most common value people paste into a form to see what happens, and a validator that accepts it is too loose.
A validator
Normalise first. People type the number as it appears on their letter, with spaces, or as nine characters run together, or in lower case. Strip spaces and hyphens, upper-case it, then check.
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));
}
isValidNino('AB 12 34 56 C'); // true
isValidNino('QQ 12 34 56 C'); // false: Q is never used
isValidNino('GB 12 34 56 A'); // false: GB is not allocated
isValidNino('AO 12 34 56 A'); // false: second letter O
And in Python, for a back end or a data clean-up:
import re
BANNED = set("DFIQUV")
UNALLOCATED = {"BG", "GB", "NK", "KN", "TN", "NT", "ZZ"}
def is_valid_nino(value: str) -> bool:
v = re.sub(r"[\s-]", "", value.upper())
if not re.fullmatch(r"[A-Z]{2}\d{6}[A-D]", v):
return False
if v[0] in BANNED or v[1] in BANNED or v[1] == "O":
return False
return v[:2] not in UNALLOCATED
The National Insurance number validator on this site runs the same rules and explains which one a number fails.
Should the suffix be required?
HMRC issues every number with a suffix, and HMRC's own systems expect it. Some older systems and some documents omit it, and some people do not know theirs. For a payroll system, require it. For a customer form where the NINO is one field among many, accept its absence and flag it for follow-up rather than blocking the user. Whichever you choose, the regular expression above is easy to adjust: make the final [A-D] optional.
What a valid number proves
Nothing about identity. A NINO that passes every rule above is well formed; it may or may not be issued, and if issued it may or may not belong to the person quoting it. HMRC does not offer a public lookup. Employers verify a new starter's NINO through HMRC's PAYE processes, and regulated businesses that need to confirm identity use document checks or an electronic identity verification service, not the NINO.
A NINO is also not a secret in the way a password is. It appears on payslips, P60s and letters, and it is routinely shared with employers, pension providers and HMRC-registered agents. It is personal data under UK GDPR, and should be handled as such, but a system that treats possession of a NINO as proof of identity has made a mistake.
National Insurance numbers in test data
HMRC reserves no range for testing. There is no equivalent of the NHS 999 range, so any number that follows the rules could in principle be issued. In practice:
- Generate rather than copy. Never put a real employee's or customer's number in a fixture, a screenshot or a demo. The validator and generator produces format-valid numbers that avoid the administrative prefixes.
- Keep generated numbers out of HMRC systems. HMRC's developer sandbox documents the specific test NINOs its APIs expect; use those for integration tests with HMRC and generated numbers everywhere else.
- Pair with fictional people. A real name next to a generated NINO is still a real person in your test database. Use the name generator and the UK address generator for the rest of the record, or the test data generator for complete personas.
For the general case, using real customer data in test environments explains why this matters under UK GDPR, and test data management compares the approaches.
Related identifiers
The NINO is one of several UK identifiers that turn up in onboarding forms and each has its own rules. The NHS number has a check digit and a reserved test range. The UK VAT number has check digits under two schemes. The company registration number has a jurisdiction prefix. A form that collects more than one of them should validate each against its own format, and a test data set should generate each one correctly.
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 NHS Number Format and Check Digit Explained
- 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