1. Check Digit Algorithm for NPI using Luhn algorithm
A National Provider Identifier or NPI is a unique 10-digit identification number issued to health care providers in the United States by the Centers for Medicare and Medicaid Services (CMS). A 10-digit NPI Number may be validated using the Luhn algorithm by prefixing "80840" to the 10-digit number (80 indicates health applications and 840 indicates the United States).
The last digit is the check digit. So the check is performed on the first 9 digits so that the last digit is obtained.
1.1 Steps Involved
- Take only the first 9 digits from the NPI to be validated
- Prefix 80840 to the number from step 1
- Double the value of alternate digits beginning with the rightmost digit.
- Add the individual digits of the products resulting from step 3 to the unaffected digits from the original number.
- Subtract the total obtained in step 4 from the next higher number ending in zero. This is the check digit. If the total obtained in step 4 is a number ending in zero, the check digit is zero.
- If the check digit is equal to the 10th digit in the NPI, then the given NPI is valid.
NPI to be validated : 1558598797
Step 1: Take only the first 9 digits from NPI
Step 2: Prefix 80840 to the above number
8 0 8 4 0 1 5 5 8 5 9 8 7 9
Step 3: Double the value of alternate digits, beginning with the rightmost digit.
Step 4: Add the individual digits of products of doubling, plus unaffected digits.
8 + 0 + 8 + 8 + 2 + 5 + 1 + 0 + 8 + 1 + 0 + 9 + 1 + 6 + 7 + 1 + 8 = 73
Step 5: Subtract from next higher number ending in zero.
Step 6: If the check digit is equal to the 10th digit in the NPI, then the given NPI is valid.