Mathwords logoMathwords

Kaprekar Routine — Definition, Formula & Examples

The Kaprekar Routine is a process where you take a number, arrange its digits in descending order and ascending order, then subtract the smaller from the larger. Repeating this process eventually leads to a fixed point or cycle — for four-digit numbers, it always reaches 6174, known as the Kaprekar constant.

Given a positive integer with nn digits (not all identical), define the function KK that maps the number to the difference between the number formed by arranging its digits in non-increasing order and the number formed by arranging its digits in non-decreasing order. The Kaprekar Routine is the iteration of KK. For n=4n = 4, the unique fixed point of KK is 61746174; for n=3n = 3, the fixed point is 495495.

How It Works

Pick any number whose digits are not all the same (like 3524, but not 1111). Arrange the digits from largest to smallest to get the "big" number, and from smallest to largest to get the "small" number. Subtract the small number from the big number. Take the result and repeat the process. For any four-digit number, you will reach 6174 in at most 7 steps, and then the routine locks on 6174 forever since 76411467=61747641 - 1467 = 6174.

Worked Example

Problem: Apply the Kaprekar Routine to the number 2005.
Step 1: Arrange digits in descending and ascending order, then subtract.
52000025=51755200 - 0025 = 5175
Step 2: Repeat with 5175.
75511557=59947551 - 1557 = 5994
Step 3: Repeat with 5994.
99544599=53559954 - 4599 = 5355
Step 4: Repeat with 5355.
55533555=19985553 - 3555 = 1998
Step 5: Repeat with 1998.
99811899=80829981 - 1899 = 8082
Step 6: Repeat with 8082.
88200288=85328820 - 0288 = 8532
Step 7: Repeat with 8532.
85322358=61748532 - 2358 = 6174
Answer: After 7 iterations, the routine reaches the Kaprekar constant 6174.

Why It Matters

The Kaprekar Routine is a classic example of how simple rules on digits can produce surprising, predictable behavior. It appears in recreational mathematics and enrichment courses, and it builds intuition about fixed points and iteration — ideas that resurface in algebra and computer science.

Common Mistakes

Mistake: Forgetting to pad with leading zeros when a result has fewer than four digits (e.g., treating 0025 as just 25).
Correction: Always keep the same number of digits. If the result is 198, write it as 0198 so you subtract 0189 from 9810, not 189 from 981.