Member Count: 598,233 - December 6, 2013  [Get Time]
 NPI Validation using Luhn Algorithm
Added by cyberjag , last edited by cyberjag on Jul 23, 2012  (view change)
Labels:
(None)

## 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

1. Take only the first 9 digits from the NPI to be validated
2. Prefix 80840 to the number from step 1
3. Double the value of alternate digits beginning with the rightmost digit.
4. Add the individual digits of the products resulting from step 3 to the unaffected digits from the original number.
5. 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.
6. If the check digit is equal to the 10th digit in the NPI, then the given NPI is valid.

### 1.2 Examples

NPI to be validated : 1558598797

Step 1: Take only the first 9 digits from NPI

`1 5 5 8 5 9 8 7 9`

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.

`0 8 2 10 10 16 18`

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.

`80-73 = 7`

Step 6: If the check digit is equal to the 10th digit in the NPI, then the given NPI is valid.

`Check Digit is 7`

## References

 Home  |   About TopCoder  |   Press Room  |   Contact Us  |   Privacy  |   Terms Developer Center  |   Corporate Services Copyright TopCoder, Inc. 2001-