Kaprekar’s Constant
Calculator
Enter any 4-digit number and watch it converge to 6174 — the mysterious mathematical “black hole” discovered by D. R. Kaprekar — with an animated flow diagram, step-by-step breakdown, and iteration table.
Kaprekar’s Constant Calculator: Explore the Mystery of 6174
Take any four-digit number where not all digits are the same. Arrange its digits in descending order to form the largest possible number. Arrange them in ascending order to form the smallest. Subtract the smaller from the larger. Repeat the process with the result. Within at most 7 steps, you will always arrive at the same number: 6174. Always. This remarkable mathematical phenomenon — known as Kaprekar’s Constant — was discovered by Indian mathematician D. R. Kaprekar in 1949, and it remains one of the most captivating curiosities in recreational mathematics. This free calculator performs the Kaprekar routine on any valid 4-digit number, displaying every iteration in a flow diagram, step-by-step breakdown, and detailed iteration table.
🔢 The Kaprekar Routine:
1. Take a 4-digit number (not all digits the same)
2. Arrange digits in descending order → largest number
3. Arrange digits in ascending order → smallest number
4. Subtract: largest − smallest = new number
5. Repeat until you reach 6174 (guaranteed in ≤ 7 steps)
Example: 3524 → 5432−2345=3087 → 8730−0378=8352 → 8532−2358=6174 ✓
The Story of D. R. Kaprekar
Dattatreya Ramchandra Kaprekar (1905–1986) was an Indian mathematician and schoolteacher from Devlali, Maharashtra. Working largely in isolation without formal academic connections to major research institutions, Kaprekar explored number theory as a passionate hobby alongside his teaching career. He published his discovery of the 6174 constant in 1949, but the mathematical establishment initially paid little attention. It wasn’t until mathematician Martin Gardner featured the discovery in his “Mathematical Games” column in Scientific American that Kaprekar’s work gained international recognition.
Kaprekar was a prolific discoverer of number patterns. Beyond the 6174 constant, he identified several other mathematical concepts that now bear his name: Kaprekar numbers (numbers whose squares can be split into parts that sum to the original number, like 45² = 2025, and 20+25 = 45), self numbers (numbers that cannot be generated by adding any number to its digit sum), and Harshad numbers (numbers divisible by their digit sum). His legacy demonstrates that mathematical discovery doesn’t require institutional affiliation — just curiosity and persistence.
Why 6174 Is Special
Mathematical black hole
Like a gravitational black hole, 6174 “attracts” all valid 4-digit numbers. Once you enter the Kaprekar routine, there’s no escape — every path leads to 6174, and 6174 maps to itself (7641−1467=6174).
Maximum 7 steps
No valid 4-digit number takes more than 7 iterations to reach 6174. Most reach it in 3–5 steps. The distribution: 1 step (357 numbers), 2 steps (519), 3 steps (2,124), 4 steps (1,124), 5 steps (1,379), 6 steps (1,508), 7 steps (1,980).
Self-reproducing
6174 is a fixed point: 7641 − 1467 = 6174. Applying the routine to 6174 returns 6174 forever. This self-reproduction is what makes it a “constant” — once reached, it never changes.
Repdigit exception
Numbers with all identical digits (1111, 2222, …, 9999) produce 0000 on the first step (1111→1111−1111=0000) and never reach 6174. These 9 numbers are the only exceptions among all 4-digit numbers.
Worked Examples of the Kaprekar Routine
| Start | Step 1 | Step 2 | Step 3 | Steps |
|---|---|---|---|---|
| 3524 | 5432−2345=3087 | 8730−0378=8352 | 8532−2358=6174 | 3 |
| 1000 | 1000−0001=0999 | 9990−0999=8991 | 9981−1899=8082 → … →6174 | 5 |
| 2111 | 2111−1112=0999 | 9990−0999=8991 | → … → 6174 | 5 |
| 9831 | 9831−1389=8442 | 8442−2448=5994 | 9954−4599=5355 → … →6174 | 7 |
| 6174 | 7641−1467=6174 | — | — | 1 (fixed) |
Mathematical Properties of 6174
Beyond its role as Kaprekar’s Constant, 6174 has several interesting mathematical properties. It is divisible by many small numbers: 6174 = 2 × 3 × 3 × 7 × 7 × 7 (its prime factorisation). It is a Harshad number (divisible by the sum of its digits: 6+1+7+4 = 18, and 6174 ÷ 18 = 343). The number 343 in that quotient is itself noteworthy: 343 = 7³. So 6174 = 18 × 7³ — a surprisingly elegant factorisation for a number discovered through a seemingly arbitrary arithmetic process.
The number 6174 is not prime (it has multiple factors), and it is not a perfect square, cube, or other perfect power. It is, however, the only 4-digit fixed point of the Kaprekar routine — no other 4-digit number maps to itself under descending-ascending-subtract. This uniqueness is part of what makes 6174 special: among the 8,991 valid 4-digit numbers (9,000 total minus 9 repdigits), every single one eventually reaches this one specific value.
Why Do All Numbers Converge?
The convergence of the Kaprekar routine is not obvious from the formula — it has been proven by exhaustive computation (checking all 8,991 valid 4-digit numbers) rather than by an elegant mathematical proof from first principles. The basic intuition is that the descending-minus-ascending subtraction rapidly reduces the “spread” of a number’s digits, pulling diverse digit arrangements toward a narrow set of intermediate values that all funnel into 6174. The routine acts as a contractive mapping — each step brings the number closer to the attractor — but the detailed mechanism involves the interplay of digit-sorting and subtraction in ways that resist simple algebraic characterisation.
Computer verification confirms that every valid 4-digit number reaches 6174, with the step count distribution heavily weighted toward 3–7 steps. The one-step numbers (like 6174 itself and numbers whose first subtraction directly yields 6174) are relatively rare, while the majority of numbers take 3–6 steps. The seven-step maximum is achieved by several numbers, with 9831 being a well-known example of the longest path.
Kaprekar’s Constant in Other Bases and Digit Counts
The Kaprekar routine generalises to other digit counts and number bases, though the results differ. For 3-digit numbers, the routine converges to 495 (the 3-digit Kaprekar constant) in at most 6 steps. For 5 digits and above, the situation becomes more complex — instead of converging to a single constant, the routine may cycle through multiple values. For 5-digit numbers, the routine can reach either 0 (from repdigits) or cycle through values without settling on a single constant, though some 5-digit starting values do reach fixed points.
In different number bases, each digit count has its own Kaprekar constant (or cycle). In base 5 with 4 digits, the constant is 3032₅. In base 8, it’s 3178₈. These generalised Kaprekar constants are an active area of recreational mathematics research, with number theorists cataloguing the fixed points and cycles for various base-digit-count combinations. The 4-digit base-10 constant (6174) remains the most famous because of its clean convergence and the accessibility of decimal arithmetic.
Classroom Applications
The Kaprekar routine is widely used in mathematics education for several pedagogical reasons. It provides a compelling introduction to algorithmic thinking — students follow a clear, repeatable procedure and observe a surprising result. It demonstrates that simple operations (sorting digits and subtracting) can produce emergent behaviour that isn’t obvious from the rules themselves. And it’s inherently engaging — the “black hole” metaphor captures students’ imagination and motivates them to test more numbers, essentially performing mathematical research through play.
Teachers use the Kaprekar routine to teach place value (understanding that digit position affects value), subtraction with borrowing (the descending-minus-ascending step requires careful multi-digit subtraction), pattern recognition (students notice that certain intermediate values recur frequently), and mathematical proof by exhaustion (discussing how the convergence is verified by checking all cases). The calculator supports classroom use by instantly showing the full iteration path for any student-chosen number, allowing rapid exploration and hypothesis testing.
Recreational Mathematics and Number Curiosities
Kaprekar’s Constant belongs to the rich tradition of recreational mathematics — the exploration of mathematical puzzles, patterns, and curiosities for intellectual pleasure rather than practical application. Other famous examples in this tradition include the Collatz conjecture (the 3n+1 problem, where iterating a simple rule on any positive integer appears to always reach 1), happy numbers (where repeatedly summing the squares of digits eventually reaches 1), and narcissistic numbers (numbers that equal the sum of their digits raised to the power of the digit count, like 153 = 1³+5³+3³).
What distinguishes Kaprekar’s Constant from many recreational math problems is that it is fully proven for the 4-digit case — the convergence is a theorem, not a conjecture. Every valid 4-digit number reaches 6174, period. This certainty makes it an excellent gateway into mathematics for people who find unsolved problems intimidating — the Kaprekar routine offers the satisfaction of a complete, verified result while still feeling magical and surprising.
Fun Facts About 6174
- Self-reproducing: 7641 − 1467 = 6174. The routine applied to 6174 returns 6174 forever.
- Discovered in 1949 by D. R. Kaprekar, an Indian schoolteacher with no formal research position.
- Maximum 7 steps for any valid 4-digit number — no number takes 8 or more iterations.
- Divisible by 18: 6174 ÷ 18 = 343 = 7³. The prime factorisation is 2 × 3² × 7³.
- Called a “mathematical black hole” because all valid numbers are inevitably pulled toward it.
- Only 9 exceptions: 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999 (repdigits).
- The 3-digit equivalent is 495 — discovered by the same process applied to 3-digit numbers.
Related Math Calculators
Frequently Asked Questions
Understanding the Convergence Flow Diagram
The calculator generates an interactive flow diagram that visually traces your number’s journey to 6174. Each node represents a number in the sequence, connected by arrows showing the transformation. The starting number appears in a purple box at the top. Each subsequent result appears below, with the subtraction operation (descending − ascending) annotated alongside the connecting arrow. The final node — 6174 — appears in green with a checkmark, clearly marking the convergence point. This visual representation makes the “black hole” metaphor tangible: you can see the sequence of numbers being pulled downward toward the attractor, with no path leading away from 6174 once it’s reached.
The flow diagram is especially valuable for comparing different starting numbers. Try several numbers in sequence and observe how different paths converge — some take direct routes (3 steps), while others meander through 5, 6, or 7 intermediate values before arriving at 6174. The visual makes it immediately apparent which numbers are “close” to 6174 (few steps) and which are “far” (many steps), creating an intuitive map of the Kaprekar landscape that tables of numbers alone can’t convey.
Step Count Distribution: How Fast Do Numbers Converge?
Among the 8,991 valid 4-digit numbers (10,000 minus the 9 repdigits minus the number 0000), the step count distribution reveals interesting patterns. Numbers reaching 6174 in exactly 1 step (356 numbers) include all numbers whose descending-minus-ascending subtraction directly yields 6174 — numbers like 7641 (7641−1467=6174), 7443 (7443−3447=3996→… wait, that’s not 1 step — actually, the 1-step numbers are those where the very first subtraction gives 6174). Numbers taking exactly 7 steps — the maximum — include 9831, which follows a particularly long path through several intermediate values before finally arriving at 6174.
The most common step count is 3 steps (2,124 numbers), followed by 6 steps (2,016 numbers). The distribution is not symmetric — there are more numbers taking 5+ steps than 1–2 steps, suggesting that most 4-digit numbers are “far” from 6174 in the Kaprekar distance metric. This distribution data, combined with the calculator’s ability to test any specific number, allows students and math enthusiasts to explore the statistical landscape of the Kaprekar routine.
The Kaprekar Routine and Computational Thinking
The Kaprekar routine is an excellent introduction to computational thinking — the problem-solving approach that underlies all of computer science. It demonstrates several key concepts: iteration (repeating a process until a condition is met), convergence (the process always terminates at a known value), fixed points (6174 maps to itself), and algorithm design (the routine is a well-defined sequence of steps that any person or computer can follow without ambiguity).
For computer science students, implementing the Kaprekar routine is a classic beginner programming exercise. It requires: input validation (checking for 4 digits and non-repdigit), string manipulation (sorting digits), number-string conversion (treating numbers as both numeric values and digit sequences), loop control (repeating until 6174 is reached or a cycle is detected), and output formatting (displaying the step-by-step process). The calculator on this page is itself an implementation of this exercise in JavaScript, demonstrating how the abstract algorithm translates to working code.
More advanced computational explorations include: finding the complete graph of all Kaprekar transitions (which 4-digit numbers lead to which next values), identifying the “basins of attraction” (groups of starting numbers that follow identical paths from some point onward), computing the step-count distribution programmatically (looping through all 8,991 valid numbers), and extending the routine to other digit counts and number bases. These exercises scale from introductory to research-level computational projects, all rooted in the same simple routine.
Connections to Other Mathematical Concepts
The Kaprekar routine connects to several areas of mathematics beyond recreational number theory. In dynamical systems theory, 6174 is a fixed-point attractor — a stable equilibrium that neighbouring states converge toward. The Kaprekar routine defines a discrete dynamical system on the set of 4-digit numbers, and 6174 is its unique global attractor (excluding the repdigit degenerate cases). This connects Kaprekar’s elementary discovery to the sophisticated mathematics of stability, attractors, and basin structures in dynamical systems.
In combinatorics, the routine raises questions about the structure of digit permutations and their subtraction properties. Why does the descending-minus-ascending operation have a unique fixed point for 4 digits but cycles for 5+ digits? This question remains partially open — we know the answers empirically (through computation) but lack a unifying theoretical framework that predicts the behaviour for arbitrary digit counts without exhaustive checking.
In information theory, the Kaprekar routine can be viewed as an entropy-reducing process — each step reduces the “information content” of the digit arrangement until reaching the minimal-entropy state (6174, which maps only to itself). The routine’s guaranteed convergence means it always compresses information, never creates new variety — a property that connects to fundamental concepts in thermodynamics and information theory about irreversible processes.
6174 in Popular Culture and Media
Kaprekar’s Constant has appeared in numerous popular mathematics books, YouTube videos, and educational media. The Numberphile YouTube channel (over 4.5 million subscribers) featured 6174 in a video that introduced the concept to a wide audience. Martin Gardner’s column in Scientific American (running from 1956 to 1981) was instrumental in bringing Kaprekar’s work to Western mathematical audiences. The number has been featured in puzzle books, mathematics competitions, and educational curricula worldwide as an accessible entry point into number theory.
The “mathematical black hole” metaphor has made 6174 particularly shareable on social media, where it regularly appears in “mind-blowing math facts” compilations. The routine’s simplicity — anyone who can sort four digits and subtract can perform it — combined with its surprising result makes it one of the most accessible demonstrations that mathematics contains genuine mysteries. Unlike many advanced mathematical results that require years of study to appreciate, the Kaprekar routine can be fully understood and personally verified by anyone with basic arithmetic skills, making it a powerful tool for mathematical outreach and public engagement.
Exploring Beyond 6174: Extensions and Variations
Mathematicians have explored many variations of the Kaprekar routine: different digit counts (2 digits → cycle between 0 and 9, or converge to multiples of 9; 3 digits → 495; 4 digits → 6174; 5+ digits → various cycles), different number bases (each base has its own set of Kaprekar constants), modified operations (using addition instead of subtraction, or alternating between addition and subtraction), and higher-dimensional analogues (applying similar sorting-and-operating processes to matrices or multi-digit arrays).
For the curious reader, here are some starting points for further exploration. The 2-digit Kaprekar routine doesn’t converge to a constant — instead, it reaches 0 for numbers with identical digits, or cycles. The 3-digit routine converges to 495 in at most 6 steps (try it: 321 → 198 → 792 → 693 → 594 → 495). For 5 digits, the routine may converge to 0 (from repdigits) or cycle through sets like {53955, 59994} or reach the fixed point 63954, depending on the starting number. These extensions show that the clean, single-attractor behaviour of the 4-digit case is actually a special property of that specific digit count — making 6174 even more remarkable.
Why This Matters for STEM Education
The Kaprekar routine exemplifies why recreational mathematics matters for STEM education. It provides an accessible, engaging entry point that develops genuine mathematical skills: algorithmic thinking, pattern recognition, hypothesis formation and testing, computational verification, and mathematical communication. Students who explore the Kaprekar routine are practicing the same cognitive skills used in advanced mathematics and computer science — just at a level where the arithmetic is simple enough to focus on the concepts rather than the computation.
For teachers, the routine offers flexible lesson design across multiple grade levels. Elementary students can practice multi-digit subtraction by performing the routine by hand. Middle school students can explore the step-count distribution and form hypotheses about which numbers converge fastest. High school students can write programs to verify convergence for all 8,991 valid numbers. University students can investigate the dynamical systems theory, explore other bases and digit counts, and attempt to characterise the convergence mechanism theoretically. The same simple routine supports progressively deeper mathematical engagement across the entire educational spectrum.
Kaprekar’s Other Discoveries
While 6174 is his most famous discovery, Kaprekar identified several other number-theoretic concepts that bear his name and remain actively studied. Kaprekar numbers are numbers whose squares can be split into two parts that sum to the original number. For example, 45² = 2025, and 20 + 25 = 45. Other Kaprekar numbers include 9 (81 → 8+1=9), 297 (88209 → 88+209=297), and 703 (494209 → 494+209=703). The sequence of Kaprekar numbers has connections to digital root theory and modular arithmetic.
Self numbers (also called Kaprekar’s self numbers or Colombian numbers) are integers that cannot be expressed as the sum of any other integer and its digit sum. For example, 20 is not a self number because 14 + (1+4) = 20 — there exists a “generator” (14) for 20. But 20 is a self number’s generator: 20 + (2+0) = 22. The number 1 is a self number because no positive integer n satisfies n + digit_sum(n) = 1. The concept connects to additive number theory and has applications in error-detecting codes.
Harshad numbers (from the Sanskrit “harsha” meaning joy, and “da” meaning giving — literally “joy-giving numbers”) are integers divisible by the sum of their digits. The number 18 is Harshad because 1+8=9 and 18÷9=2. All single-digit numbers are Harshad, and the concept extends to any number base. Kaprekar’s Constant 6174 is itself a Harshad number (6+1+7+4=18, 6174÷18=343), adding another layer of mathematical elegance to an already remarkable number. Kaprekar’s systematic exploration of these number classes, conducted largely through manual computation and geometric intuition, laid groundwork that later mathematicians formalised and extended using computers — demonstrating that fundamental discoveries can emerge from careful observation and tireless experimentation, even without institutional support or modern computational tools.
Together, these discoveries paint a picture of a mathematician whose curiosity ranged across the entire landscape of number properties. Kaprekar didn’t limit himself to one type of number pattern — he systematically explored how digits relate to the numbers they compose, how arithmetic operations create unexpected fixed points, and how simple rules generate complex behaviour. His body of work, accumulated over decades of solo exploration, collectively established him as one of the most original contributors to recreational and elementary number theory in the twentieth century. The calculator above continues his tradition: it invites anyone with curiosity and a 4-digit number to experience the same sense of mathematical wonder that drove Kaprekar’s lifelong exploration.
Try a number now
Enter any 4-digit number and watch it converge to the mysterious 6174 — the mathematical black hole.
Explore 6174 ↑