← Back to list

The Magical Number 6174

Why Every Four-Digit Number Finds Its Way to Kaprekar’s Constant

Vagelis Plevris in ThinkArt · 2026-04-07 00:06 · 849 claps · 7.2 min read paywalled
#math #algorithms #technology #science #mathematics
Open on Medium ↗
Wiki topics: 💻 · Programming 📐 · Mathematics 🔬 · Science · General

MATHEMATICAL MYSTERIES

The Magical Number 6174

Why Every Four-Digit Number Finds Its Way to Kaprekar’s Constant

There is a number in mathematics that feels almost like a trick.

No matter how you start, no matter what four-digit number you choose, as long as its digits are not all the same, you always end up in the same place.

That number is 6174.

It is known as Kaprekar’s Constant, and once you encounter it, it is very hard to forget.

A simple game with numbers

Let us begin with a small experiment.

Take any four-digit number, as long as not all digits are the same. We allow leading zeros, so numbers like 0378 or 0010 are included.

Rearrange the digits to form the largest possible number, then the smallest (allowing leading zeros), subtract the two, and repeat.

This is known as the Kaprekar routine.

At first, it looks like a harmless numerical game. But something remarkable happens. No matter which valid number you choose, the process always leads to the same result: 6174.

A quick example

Let us try it. Start with: 4321

  • Largest: 4321, Smallest: 1234
  • Subtract: 4321 − 1234 = 3087

Repeat:

  • 8730 − 0378 = 8352
  • 8532 − 2358 = 6174

In just three steps, we arrive at the same mysterious number.

Try: 1605

6510 − 0156 = 6354 6543 − 3456 = 3087 8730 − 0378 = 8352 8532 − 2358 = 6174

Try it with other numbers. You will see the same thing again and again.

Seven different starting numbers, each converging to Kaprekar’s constant (6174) in a different number of steps, from 1 to 7 iterations.

Seven different starting numbers, each converging to Kaprekar’s constant (6174) in a different number of steps, from 1 to 7 iterations.

The essential rule

There is one simple condition for this process to work: the starting number must not have all digits identical.

If all digits are the same, such as 1111 or 2222, the largest and smallest rearrangements are identical, so their difference is zero. From that point on, the process remains at zero and no longer evolves.

This restriction removes only a handful of cases. Among the 10,000 four-digit numbers from 0000 to 9999, allowing leading zeros, there are exactly ten numbers with identical digits, namely 0000, 1111, up to 9999. Excluding these leaves 10,000 – 10 = 9990 valid starting numbers.

For all of these, the same phenomenon appears: the sequence inevitably converges to 6174.

The man behind the number

The constant is named after D. R. Kaprekar, an Indian schoolteacher who spent his life exploring numbers out of pure curiosity. He had no advanced academic training and worked outside the mathematical establishment, teaching in a small town in India for his entire career.

D. R. Kaprekar (1905–1986), Indian recreational mathematician. Image source: Wikipedia (fair use), original source: Politecnico di Torino.

D. R. Kaprekar (1905–1986), Indian recreational mathematician. Image source: Wikipedia (fair use), original source: Politecnico di Torino.

Kaprekar approached mathematics very differently from most researchers. He was not interested in abstraction for its own sake. Instead, he experimented with numbers, searched for patterns, and followed simple ideas wherever they led. Much of his work was published in modest journals, and some of it he even printed himself.

His contemporaries often dismissed his ideas as trivial. Yet he continued, driven by an almost obsessive fascination with numbers. He once described it in his own words:

“A drunkard wants to go on drinking wine to remain in that pleasurable state. The same is the case with me in so far as numbers are concerned.”

Working largely in isolation, he discovered a remarkable collection of numerical patterns, including Kaprekar numbers, self numbers, and harshad numbers.

But recognition came late. It was only in the 1970s, when the American mathematician Martin Gardner (1914–2010) wrote about his work in Scientific American, that the mathematical community began to appreciate what he had found.

In the case of 6174, what looks like a simple numerical trick turns out to be something much deeper. Behind it lies a system with a surprisingly strong internal structure, one that Kaprekar uncovered through patience, curiosity, and an unusual way of thinking about numbers.

How fast does the process converge?

At this point, the natural question is no longer whether the process reaches 6174, but how quickly it gets there.

The answer is surprisingly sharp. No valid four-digit number takes more than seven iterations to reach 6174. In that sense, the convergence is inevitable and remarkably fast.

If we examine all of the 9990 valid starting numbers, a very clear pattern appears. The most common case is convergence in 3 iterations. In fact, 2400 numbers, or 24.02% of all valid starting points, reach 6174 in exactly three steps. At the other end, 2184 numbers require the maximum of 7 iterations. So while the process is always fast, it is not concentrated only near the beginning. A substantial portion of numbers take the full allowed length before settling down.

The complete distribution is shown in the bar chart below.

Bar chart showing the distribution of iterations needed for all 9990 valid four-digit numbers to reach Kaprekar’s constant 6174.

Bar chart showing the distribution of iterations needed for all 9990 valid four-digit numbers to reach Kaprekar’s constant 6174.

What is striking here is the shape of the distribution. Only one number, 6174 itself, requires zero iterations, since it is already at the fixed point. Very few numbers arrive in one or two steps. Most of the mass lies between three and seven iterations, which means that the routine usually needs a short but nontrivial sequence of transformations before the digits settle into their final configuration.

This is part of what makes Kaprekar’s constant so appealing. The process is neither instantaneous nor erratic. It is structured, bounded, and universal. Every valid path ends at the same place, and none of them wander for long.

How many different cases are there?

The first thing to notice is that after one step, you are no longer really working with numbers in the usual sense. Once you sort the digits, the original order disappears. Numbers like 3528, 8352, and 2385 all become indistinguishable. The process forgets where you started and keeps only the digits themselves.

This drastically reduces the number of distinct situations that can occur. Instead of 9990 possible starting numbers, we are effectively working with only 705 different digit combinations, obtained by grouping together all permutations of the same digits.

To see where this number comes from, notice that after sorting, a number is determined only by its digits, not their order. So we are counting how many ways we can choose 4 digits from the set {0,1,2,…,9}, allowing repetition and ignoring order.

This is a classic combinatorial problem: selecting k elements from n types with repetition allowed. The number of such combinations is

Here, n = 10 (digits 0 through 9) and k = 4, so

From these, we exclude the trivial cases where all digits are identical, such as 0000, 1111, …, 9999. There are exactly 10 such cases, so we are left with 715 – 10 = 705.

So the 9990 valid starting numbers collapse into just 705 distinct digit patterns. The system becomes much smaller, and much more constrained, than it first appears.

Why does everything lead to 6174?

Once this reduction has taken place, the dynamics become easier to understand. The subtraction step introduces a strong asymmetry. By always subtracting the smallest arrangement from the largest, the process pushes the digits toward a particular structure, typically with larger digits at the front and smaller ones at the end. The transformation is not neutral. It systematically reshapes the number at every step.

At the same time, the system is finite. There are only 705 possible digit configurations, and the process is deterministic. It cannot continue producing new states forever. Eventually, it must repeat. When that happens, the sequence either enters a cycle or settles into a fixed point.

What is remarkable is that, for this system, there is essentially only one non-trivial outcome. Apart from the trivial case of zero, every valid starting number is drawn into the same fixed point: 6174.

In other words, 6174 is not just a number that appears frequently. It is the inevitable endpoint of the process.

Why 6174 stays unchanged

Once the process reaches 6174, it locks into place. Rearranging its digits gives 7641 as the largest number and 1467 as the smallest, and their difference is again 6174. From that point on, nothing changes.

This is not an accident. In the standard four-digit Kaprekar routine in base 10, 6174 is the only non-trivial fixed point. No other valid four-digit number with at least two distinct digits maps to itself under the same process.

Within this system, the picture is complete. Once you arrive at 6174, the process has reached equilibrium, and there is nowhere else to go.

Could it have been another number?

This is perhaps the most interesting question. Why does everything lead to 6174, and not to some other value?

The answer lies in the structure of the problem. The result depends on working in base 10, using exactly four digits, and applying this specific rule of sorting and subtracting. If any of these ingredients change, the behavior changes as well.

For instance, if you repeat the same process with three-digit numbers, the system converges to 495 instead. In that case too, the number is stable under the same operation.

But the pattern does not continue indefinitely. For other digit lengths, the process does not always settle into a single fixed point. Sometimes it produces cycles, where the sequence keeps repeating several values instead of collapsing into one. This makes the four-digit case particularly special: it is one of the rare situations where everything converges cleanly to a single number.

A small mystery that keeps pulling you in

Kaprekar’s Constant shows how simple rules can produce behavior that feels almost inevitable. The procedure removes information by sorting digits and imposes structure through subtraction, gradually narrowing all possibilities until only one remains.

What begins as a small numerical game turns into something more structured, almost like a system with its own internal gravity.

So try it yourself. Pick any four-digit number and run the process.

And when you arrive at 6174, as you inevitably will, you may feel that you have discovered something.

But in a deeper sense, you were being led there all along.

Cover image: Kaprekar’s constant, 6174, the number every valid four-digit sequence is drawn toward. Generated with AI tools for this article.


메타데이터
post_id
40a8495023a5
slug
the-magical-number-6174-40a8495023a5
url
https://medium.com/think-art/the-magical-number-6174-40a8495023a5
canonical_url
https://medium.com/think-art/the-magical-number-6174-40a8495023a5
author_url
https://medium.com/@vplevris
status
ok
fetched_at
2026-07-15 10:47:00