If you have ever used the SA ID Number Checker on this site, you will have noticed it can instantly tell you whether an ID number is valid or not — before checking anything with Home Affairs. It does this using a formula called the Luhn algorithm.
The Luhn algorithm is a simple checksum formula used worldwide to detect accidental errors in identification numbers. It was created in 1954 by Hans Peter Luhn, a scientist at IBM, and was granted a patent in 1960. Today it is used to validate credit card numbers, IMEI numbers on mobile phones, and — in South Africa — every 13-digit ID number.
How the Luhn Algorithm Works
The algorithm is designed to catch the most common data entry mistakes: single mistyped digits and transposed adjacent digits. It works by performing a series of simple mathematical steps on the number.
Step-by-Step Process
Starting from the rightmost digit (the check digit) and moving left:
- Double every second digit. Starting from the second-to-last digit and moving left, multiply every other digit by 2.
- Subtract 9 from results over 9. If doubling produces a number greater than 9 (for example, 7 × 2 = 14), subtract 9 to get a single digit (14 − 9 = 5).
- Sum all the digits. Add up every digit — the doubled-and-adjusted ones and the untouched ones.
- Check the total. If the sum is divisible by 10 (i.e. ends in 0), the number is valid.
A Worked Example with a SA ID Number
Let us walk through the validation of a sample ID number: 9003155800084.
Write out the digits and number each position from the right:
9 0 0 3 1 5 5 8 0 0 0 8 4
Positions (from right): 13 12 11 10 9 8 7 6 5 4 3 2 1
Step 1 — double every second digit (positions 2, 4, 6, 8, 10 and 12), subtracting 9 from any result above 9:
- Position 2: 8 × 2 = 16 → 16 − 9 = 7
- Position 4: 0 × 2 = 0
- Position 6: 8 × 2 = 16 → 16 − 9 = 7
- Position 8: 5 × 2 = 10 → 10 − 9 = 1
- Position 10: 3 × 2 = 6
- Position 12: 0 × 2 = 0
The doubled digits add up to 7 + 0 + 7 + 1 + 6 + 0 = 21.
Step 2 — add the untouched digits in the odd positions (1, 3, 5, 7, 9, 11 and 13):
4 + 0 + 0 + 5 + 1 + 0 + 9 = 19
Step 3 — add the two subtotals together:
21 + 19 = 40
Step 4 — check the total. 40 is divisible by 10, so the number passes the Luhn check and is structurally valid.
If even one digit were mistyped — say the final 4 became a 6, pushing the total to 42 — the sum would no longer be divisible by 10 and the checker would reject the number instantly. That is exactly how the algorithm catches typos.
You can verify this yourself using our ID Number Checker — enter any 13-digit ID number and see the Luhn checksum result instantly. Developers building or testing applications that handle SA ID numbers can use our SA ID number generator to produce valid 13-digit test IDs without exposing real customer data.
What the Luhn Algorithm Catches
The formula is specifically designed to detect:
- Single-digit substitution errors — typing a 5 instead of a 3, for instance. Any single incorrect digit will cause the checksum to fail.
- Adjacent transposition errors — swapping two neighbouring digits (like 35 becoming 53). The doubling pattern means transposed digits almost always produce a different sum.
What It Does Not Catch
The Luhn algorithm is not foolproof. It cannot detect:
- Swapping 09 with 90 (or any pair where both doubled and undoubled values produce the same result)
- Multiple simultaneous errors that happen to cancel each other out
- Whether the number was actually issued — only that its structure is mathematically consistent
For this reason, a valid Luhn check means "this number could be real" — not "this number is real." Only the Department of Home Affairs can confirm actual issuance.
Where Else Is the Luhn Algorithm Used?
The Luhn algorithm is one of the most widely deployed checksum formulas in the world:
- Credit and debit cards — Visa, Mastercard, Amex, and virtually all card networks use Luhn validation
- IMEI numbers — the 15-digit identifier on every mobile phone
- National identity numbers — South Africa, Canada (SIN), and several other countries
- Loyalty card numbers, ISBN-10, and various other identification systems
Its popularity comes from its simplicity. It requires no division, no lookup tables, and can be computed mentally with practice. For computers, it takes microseconds.
Why South Africa Uses It
When the 13-digit ID number format was designed, the Department of Home Affairs needed a way to catch data entry errors before they propagated through government systems. The Luhn algorithm was the natural choice — it was already proven in the financial sector, easy to implement, and effective against the most common human mistakes.
Every time you enter your ID number on an eFiling form, a bank application, or a medical aid registration, the system runs this check before accepting your input. It is a silent guardian against typos that could cause your application to be rejected or your records to be mismatched.
Want to see it in action? Try our free SA ID Number Checker — enter any 13-digit number and watch the Luhn validation happen in real time.