Category Archives: Algorithms

Validating NPI – Luhn Algorithm

Sample NPI Number – 1295723567

Step 1 (take first 9 digits, last digit is check digit)
129572356 check digit 7

Step 2 prefix 80840
80840 129572356

Step 3 Double the value of alternate digits, beginning with the rightmost digit.
0 8 2 18 14 6 12

Step 4  Add the individual digits of products of doubling, plus unaffected digits.
unaffected digits – 5 2 5 2 0 8 8
doubled digits as individual digits 0 8 2 1 8 1 4 6 1 2
add them up 5 + 2 + 5 + 2 + 0 + 8 + 8 + 0 + 8 + 2 + 1 + 8 + 1 + 4 + 6 + 1 + 2  = 63

Step 5 Subtract from next higher number ending in zero.
next higher number = 70
70-63 = 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 indeed 7