Luhn Checksum

AID: 1809
  • Status: Published

2290 points

  • Bykaerez
  • TypeTutorial
  • Posted on2009-10-20 at 06:26:27
The Luhn checksum is often used in analog to digital systems such as
many countries ID cards, credit cards and more.

The purpose is NOT to encrypt the number but prevent simple errors
such as digit misplacement and (usually) single digit errors.

Take the following non-existant Visa credit card number:
4580 4580 4580 4580
                                    
1:

Select allOpen in new window



This number is correct using the Luhn checksum method, this doesn't mean
you can use it to shop but programmers often use it to perform a preliminary
check prior to sending it on to be approved.

How is the number checked, let's start:

4580 4580 4580 4580
                                          X
2121 2121 2121 2121
                                    
1:
2:
3:

Select allOpen in new window

[for checking always start on the right from the digit 1]
----------------------------
8570 8570 8570 8570
                                    
1:
2:

Select allOpen in new window


Note that we perform single digit multiplication, top line by bottom line, right to left:
0 X 1 = 0
8 X 2 = 16 -> 1+6 = 7
5 X 1 = 5
4 X 2 = 8
                                    
1:
2:
3:
4:

Select allOpen in new window

etc...

As you can see 8 X 2 is written as 7, if the multiplication gives a value of 10
and above always combine the two digits together (e.g. 10 -> 1+0 = 1)

8+5+7+0+8+5+7+0+8+5+7+0+8+5+7+0 = 80
                                    
1:

Select allOpen in new window



Since the right digit is 0 the number is correct!
Or in programmers language, 80 mod 10 = 0 means the number is correct, that is why Luhn is
also sometimes called MOD 10 checking.

Lets take a look at an invalid credit card number:

4580 1234 5678 9012
                                          X
2121 2121 2121 2121
----------------------------
8570 2264 1658 9022
                                    
1:
2:
3:
4:
5:

Select allOpen in new window


Again from the right column
2X1=2, 1X2=2, 0X1=0, 9X2=18=>1+8=9, 8X1=8 
                                    
1:

Select allOpen in new window

etc...

8+5+7+0+2+2+6+4+1+6+5+8+9+0+2+2 = 67
                                    
1:

Select allOpen in new window

---> INVALID!! right digit needs to be 0 to be valid!

So, how do you generate a valid number ?!
The right most digit is the check digit which is why we always begin from the right
as described in the check above.
To generate the number we will begin with the digit 2 instead of 1:

1234
          X
1212
------
1438

1+4+3+8 = 16 -> 10-[right digit] -> 10-6=4
                                    
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

THIS IS THE CHECKDIGIT
NOTE! If the right digit at this stage was 0, then that would be the checkdigit.

Lets check it:

12344
           X
12121
--------
14384

1+4+3+8+4 = 20
                                    
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

YUP! CORRECT!!
Asked On
2009-10-20 at 06:26:27ID1809
Tags

luhn

,

checksum

,

crc

,

credit

,

card

,

credit card

,

id

Topic

Miscellaneous Security

Views
1664

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Misc Security Experts

  1. breadtan

    145,843

    Master

    3,100 points yesterday

    Profile
    Rank: Genius
  2. Russell_Venable

    38,663

    0 points yesterday

    Profile
    Rank: Wizard
  3. ahoffmann

    27,636

    0 points yesterday

    Profile
    Rank: Genius
  4. richrumble

    25,321

    0 points yesterday

    Profile
    Rank: Genius
  5. DaveHowe

    17,129

    2,000 points yesterday

    Profile
    Rank: Genius
  6. SSharma

    16,184

    0 points yesterday

    Profile
    Rank: Genius
  7. younghv

    12,906

    0 points yesterday

    Profile
    Rank: Genius
  8. DaveBaldwin

    12,728

    0 points yesterday

    Profile
    Rank: Genius
  9. Tolomir

    12,268

    0 points yesterday

    Profile
    Rank: Genius
  10. ve3ofa

    11,032

    0 points yesterday

    Profile
    Rank: Genius
  11. dvt_localboy

    10,600

    0 points yesterday

    Profile
    Rank: Sage
  12. pand0ra_usa

    10,600

    0 points yesterday

    Profile
    Rank: Guru
  13. rpggamergirl

    10,364

    0 points yesterday

    Profile
    Rank: Genius
  14. abbright

    10,292

    0 points yesterday

    Profile
    Rank: Guru
  15. kode99

    9,900

    0 points yesterday

    Profile
    Rank: Genius
  16. erniebeek

    9,250

    0 points yesterday

    Profile
    Rank: Genius
  17. slemmesmi

    8,200

    0 points yesterday

    Profile
    Rank: Guru
  18. motnahp00

    8,102

    0 points yesterday

    Profile
    Rank: Sage
  19. CoccoBill

    7,364

    0 points yesterday

    Profile
    Rank: Sage
  20. giltjr

    7,187

    900 points yesterday

    Profile
    Rank: Genius
  21. tedbilly

    7,000

    0 points yesterday

    Profile
    Rank: Genius
  22. arnold

    6,800

    0 points yesterday

    Profile
    Rank: Genius
  23. MASQUERAID

    6,800

    0 points yesterday

    Profile
    Rank: Genius
  24. ZShaver

    6,800

    0 points yesterday

    Profile
    Rank: Master
  25. madunix

    6,624

    0 points yesterday

    Profile
    Rank: Sage

Hall Of Fame