How NPI Numbers Are Structured
If you have ever pasted a National Provider Identifier into a claim, a roster, or a database column, you have probably wondered: is this thing even a real NPI, or did someone fat-finger a digit? The good news is that you can answer that question without calling any registry at all. An NPI is not a random string. Its last digit is a mathematical checksum of the nine digits in front of it, so a large share of typos are catchable with arithmetic alone.
This post is the technical companion to the plain-English overview in what an NPI number is. Here we care about the bytes: how the ten positions are laid out, the exact NPI number format and check digit rules CMS publishes, a worked example you can follow by hand, and a couple of ways to validate one in code before it ever hits your system.
The 10-digit structure
An NPI is a 10-position, all-numeric identifier. That is the entire specification for the visible number — no embedded state code, no specialty, no provider type, nothing you can decode. CMS deliberately designed it as an "intelligence-free" identifier so that a provider's number never has to change when they move, switch specialties, or re-incorporate.
Concretely, the ten positions break down like this:
| Positions | Name | What it holds |
|---|---|---|
| 1–9 | Identifier | Nine digits assigned by NPPES. Position 1 is currently 1 or 2, reserving room to grow. |
| 10 | Check digit | A single Luhn checksum computed from positions 1–9. |
That first digit being a 1 or 2 is a common source of confusion. It is not the same thing as an NPI "type." Type 1 (individual) and Type 2 (organizational) are attributes stored in NPPES, not something encoded in the number — the leading 1/2 is simply where the enumerator started the sequence. If that distinction matters for your work, see Type 1 vs Type 2 NPI.
Because there is no meaning inside the digits, the only thing you can check offline is whether the number is internally consistent. That is exactly what the check digit is for.
Where the check digit comes from
CMS did not invent a new scheme. The NPI check digit uses the Luhn algorithm defined in ISO/IEC 7812, the same standard that governs card issuer identifiers (think of the numbers on the front of a payment card). Under that standard a full card identifier carries an "80840" prefix, where 80 designates health applications and 840 designates the United States. You will never see 80840 printed on a physical NPI, but it matters mathematically: the check digit is computed as if the number were 80840 + the nine-digit identifier.
The official rules and the worked example below come from the CMS document "Requirements for National Provider Identifier (NPI) and NPI Check Digit." I have kept the mechanics identical to that source so your results will match anything CMS validates against.
A worked example
Let's compute the check digit for the nine-digit identifier CMS uses in its own documentation: 123456789.
Step 1 — Double every second digit, starting from the right of the identifier.
| Digit (left→right) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Double this one? | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
| After doubling | 2 | 2 | 6 | 4 | 10 | 6 | 14 | 8 | 18 |
Step 2 — Split any two-digit product into its digits and add everything up. So 10 becomes 1+0, 14 becomes 1+4, 18 becomes 1+8:
2 + 2 + 6 + 4 + (1+0) + 6 + (1+4) + 8 + (1+8) = 43
Step 3 — Add the constant 24 for the 80840 prefix. Running the same doubling rules across the 80840 prefix contributes a fixed 24 to the sum, so CMS tells you to simply add it rather than re-derive it every time:
43 + 24 = 67
Step 4 — The check digit is whatever makes the total a multiple of 10. The next multiple of 10 above 67 is 70, and 70 − 67 = 3.
So the check digit is 3, and the complete, valid NPI is 1234567893. If someone hands you 1234567890, you now know it is malformed without looking anything up.
How to validate one programmatically
The nice part is that this is a handful of lines in any language. Here is a self-contained JavaScript function that returns true only for a syntactically valid NPI:
function isValidNpi(npi) {
// Must be exactly 10 digits
if (!/^\d{10}$/.test(npi)) return false;
const digits = npi.split('').map(Number);
const check = digits.pop(); // position 10
// Start Luhn sum with 24 for the implied 80840 prefix
let sum = 24;
digits.reverse().forEach((d, i) => {
// Double every OTHER identifier digit (the rightmost first)
if (i % 2 === 0) {
d *= 2;
if (d > 9) d -= 9; // same as summing the two digits
}
sum += d;
});
return (sum + check) % 10 === 0;
}
isValidNpi('1234567893'); // true
isValidNpi('1234567890'); // false
The d -= 9 trick is just a shortcut for splitting a doubled two-digit number into its digits (for example 14 → 1+4 = 5, and 14 − 9 = 5). The same pattern ports directly to Python, PHP, Go, or SQL.
Here is the important caveat, and it is the reason this post exists as a technical piece rather than a substitute for a real lookup:
A valid check digit only proves the number is well-formed. It does not prove the NPI was ever issued, or that it belongs to the provider you think it does. Roughly one in ten random 10-digit numbers will pass the Luhn test by pure chance. So use the check digit as a cheap first filter — reject garbage before it enters your pipeline — and then confirm the survivors against the authoritative source.
For a single number, that means the free NPI Lookup tool, which resolves the NPI to the real provider name, address, and taxonomy in NPPES. For thousands of numbers, you want the API described below, which returns the same NPPES record as structured JSON so you can fold check-digit validation and identity verification into one step. Either way, the pattern is the same: validate the format locally, then verify existence against the registry.
Common validation mistakes
A few things trip people up when they wire this into production:
- Storing NPIs as integers. Do not. Keep them as fixed-length strings. An integer column silently drops meaning if a future numbering range ever begins differently, and it makes zero-padding your problem.
- Forgetting the constant 24. If you re-implement Luhn from a generic tutorial and skip the 80840 prefix, every check digit will be wrong. The prefix is the one NPI-specific twist.
- Doubling from the wrong end. Luhn doubles alternate digits starting from the rightmost digit of the identifier (position 9), not from position 1.
- Treating "passes Luhn" as "is real." It isn't. Always reconcile against NPPES for anything that touches billing or credentialing — the free NPI Lookup is the fastest way to spot-check one by hand.
FAQ
Does an NPI encode the provider's state or specialty? No. The number is intelligence-free by design. State, specialty, and taxonomy all live in the NPPES record, not in the digits, which is why the number never changes when a provider relocates.
Why does the leading digit have to be a 1 or a 2? Those are simply the ranges NPPES has enumerated into so far. The leading digit is not a provider "type" and carries no meaning beyond sequencing — more numbers become available as the pool fills.
Can I trust an NPI just because the check digit is valid? No. A valid check digit means the number is syntactically correct, not that it was issued or belongs to a specific provider. Roughly 10% of random 10-digit numbers pass by chance, so always verify against NPPES.
Is the NPI algorithm the same one used for credit cards?
It is the same Luhn/ISO 7812 checksum family, with the health-specific 80840 prefix baked in as the constant 24. The math is identical; only the prefix differs.
Related posts
How to Find a Pharmacy's NPI (CVS, Walgreens & More)
A pharmacy NPI is a Type 2 number, and a chain like CVS or Walgreens has one per store — here's how to find the exact location and not confuse it with the NCPDP ID.
How to Find a Nurse Practitioner's NPI
Finding an NP or APRN's NPI takes a little more care than a physician's — here's how to search, read the APRN taxonomy, and confirm you have the right person.
How to Find a Dentist's NPI
Finding a dentist's NPI trips people up because dental records span individual dentists, whole practices, and staff who often have no NPI at all — here's how to land on the right one.