This is a free online Kaprekar constant calculator: enter a 3- or 4-digit number and discover, step by step, how the Kaprekar routine transforms it until it reaches the constant (6174 for 4-digit numbers, 495 for 3-digit numbers).

Run the calculation

Enter a 3- or 4-digit number (with at least two different digits):

How to calculate the Kaprekar constant in 4 steps

The Kaprekar routine (or Kaprekar operation) is an extremely simple iterative algorithm that, applied repeatedly, converges to the constant 6174 (for 4-digit numbers) or 495 (for 3-digit numbers). Here is how to proceed:

  1. Choose a number with 3 or 4 digits and at least two different digits (e.g. 3524).
  2. Rearrange the digits in descending and ascending order to obtain two numbers (5432 and 2345).
  3. Subtract the smaller number from the larger one (5432 − 2345 = 3087).
  4. Repeat the procedure on the result. In at most 7 iterations for 4-digit numbers (6 for 3-digit numbers) you will always obtain the Kaprekar constant.

Practical example: starting from 3524

Step 1: 5432 − 2345 = 3087
Step 2: 8730 − 0378 = 8352
Step 3: 8532 − 2358 = 6174  ✓

What is the Kaprekar constant?

The Kaprekar constant is the number 6174, which possesses an extraordinary property: it is the only 4-digit number that, when the Kaprekar routine is applied to itself (subtracting the ascending arrangement of its digits from the descending one), produces itself again. In mathematical terms, it is the fixed point of the routine in the space of 4-digit numbers:

7641 − 1467 = 6174

The surprising fact is that any 4-digit number with at least two different digits converges to 6174 in at most 7 iterations. The same property holds for the number 495 in the space of 3-digit numbers. In 1981 mathematicians G. D. Prichett and collaborators rigorously proved that, in base 10, 495 and 6174 are the only Kaprekar constants in the strict sense (i.e. fixed points that attract all numbers of their own length).

Who was D. R. Kaprekar?

Dattatreya Ramchandra Kaprekar (1905 – 1986) was an Indian mathematician, a self-taught schoolteacher active in the city of Devlali, in Maharashtra. He is known for his contributions to recreational mathematics and number theory. Kaprekar first described the routine now bearing his name in the article "Another Solitaire Game", published in the journal Scripta Mathematica (volume 15, pages 244–245) in 1949. Six years later, in 1955, he returned to the subject with a second article entitled "An Interesting Property of the Number 6174".

Why does one always arrive at 6174?

The explanation lies in the very structure of long subtraction. At each step, the two numbers involved in the subtraction have the same digit sum: consequently, every intermediate result is always a multiple of 9. The space of possible results narrows rapidly, and the routine ends up attracting all numbers towards the only fixed point compatible with these constraints: 6174. It is a perfect example of convergent recursive behaviour — an "attractor" in the language of dynamical systems.

Properties and curiosities

  • Numbers with all identical digits (1111, 2222, ...) are the only exception: they produce 0 at the first step.
  • For 4-digit numbers convergence occurs in at most 7 iterations according to most sources; on average 4–5 steps are sufficient.
  • For 3-digit numbers the constant is 495, reached in at most 6 iterations.
  • Both 6174 and 495 are multiples of 9: 6174 = 2 × 3² × 7³; 495 = 3² × 5 × 11.
  • For 5-digit numbers the routine does not converge to a fixed point: it ends in one of three known cycles (or in zero).
  • For 6-digit numbers there are two fixed points (549945 and 631764), but some numbers enter cycles instead.

Frequently asked questions

What is the Kaprekar constant?

The Kaprekar constant is the number 6174, a fixed point of the iterative routine discovered by the Indian mathematician Dattatreya Ramchandra Kaprekar, who described it in a 1949 article in Scripta Mathematica. Applying the routine to any 4-digit number with at least two different digits, it always converges to 6174 in at most 7 iterations.

How is 6174 calculated?

Take a 4-digit number, rearrange the digits in descending and ascending order to get two numbers, subtract the smaller from the larger and repeat the procedure on the result. In at most 7 iterations the result will be 6174.

Is there a Kaprekar constant for 3-digit numbers?

Yes: it is the number 495. Applying the same routine to a 3-digit number with at least two different digits, it converges to 495 in at most 6 iterations. G. D. Prichett and collaborators proved in 1981 that in base 10 the only strict Kaprekar constants (fixed points that attract all numbers of their own length) are 495 and 6174.

Why does one always arrive at 6174?

Because 6174 is the only fixed point of the routine in the space of 4-digit numbers: applying the routine to 6174 gives 6174 again (7641 − 1467 = 6174). Moreover every intermediate result is always a multiple of 9, which greatly restricts the space of possible paths and all numbers end up converging to the only compatible fixed point.

Does the Kaprekar constant work for numbers with 5 or more digits?

No, not in the strict sense. For 5-digit numbers the routine does not converge to a single fixed point: it ends in one of three known cycles or in zero. For 6 digits there are two fixed points (549945 and 631764), but not all numbers converge there — some enter cycles.

How many steps are needed to reach 6174?

At most 7 iterations for any 4-digit number with at least two different digits, according to Wikipedia and most sources. Wolfram's MathWorld gives 8 as the limit, probably counting cases with leading zeros differently. On average about 4–5 steps are sufficient.

Who discovered the constant 6174?

The Indian mathematician Dattatreya Ramchandra Kaprekar (1905–1986), who first described the routine in the article "Another Solitaire Game" published in Scripta Mathematica, volume 15, pages 244–245, in 1949. Kaprekar returned to the subject in subsequent articles in 1955 ("An Interesting Property of the Number 6174") and 1959.

What happens if I enter a number with all identical digits?

A number with all identical digits (such as 1111 or 333) gives 0 at the first step and the routine stops. For this reason the calculator requires at least two different digits.

Further reading

Cycles: when the routine does not converge

The Kaprekar routine does not always produce a constant. In general, starting from a number with a given number of digits, the iteration ends in one of these ways: reaching zero (if the starting number has all identical digits), reaching a Kaprekar constant (fixed point), or becoming trapped in a cycle of numbers that repeat in sequence.

For numbers with 3 and 4 digits there are no cycles: one always ends at 0, 495 or 6174. But already with 5-digit numbers three distinct cycles appear:

  • cycle of length 2: { 53955, 59994 }
  • cycle of length 4: { 61974, 82962, 75933, 63954 }
  • cycle of length 4: { 62964, 71973, 83952, 74943 }

For 6-digit numbers one arrives at 0, at the constants 549945 or 631764, or at one of various cycles. 7-digit numbers also produce a variety of cycles.

Fixed points of the routine for other digit lengths

In addition to 495 (3 digits) and 6174 (4 digits), the Kaprekar map f(n) = n' − n'' (with n' digits in descending order, n'' ascending) has other fixed points in base 10, catalogued in OEIS sequence A099009. The first ones are:

  • 3 digits: 495
  • 4 digits: 6174
  • 6 digits: 549945, 631764
  • 8 digits: 63317664, 97508421
  • 9 digits: 554999445, 864197532
  • 10 digits: 6333176664, 9753086421, 9975084201

An important terminological note: these numbers are fixed points of the map, but they are not "Kaprekar constants" in the proper sense — because, apart from 495 and 6174, they do not attract all numbers of their own length (some enter cycles). Prichett, Ludington and Lapenta proved in 1981 that 495 and 6174 are the only true "constants" in base 10.

The complete list can be consulted on the On-Line Encyclopedia of Integer Sequences at entry A099009.

The routine in bases other than 10

The Kaprekar routine can be applied in any base b, not only in base 10. In each base there are different fixed points and cycles. The systematic study of the routine's behaviour as base and digit count vary is an active research area: Anthony Kay and Katrina Downes-Ward published in 2022 and 2024, in the Journal of Integer Sequences and on arXiv, complete classifications of fixed points and cycles for even and odd bases.

The corresponding OEIS sequences are: A163205 (base 2), A164997 (base 3), A165016 (base 4), and so on up to A099009 (base 10). A simple but elegant result: in base 2 every "Kaprekar index" (k₀, k₁) with k₀ ≤ k₁ is a fixed point, and there are no cycles of length greater than 1.

Sources and further reading

  • Kaprekar, D. R. — "Another Solitaire Game", Scripta Mathematica, vol. 15, pp. 244–245, 1949.
  • Kaprekar, D. R. — "An Interesting Property of the Number 6174", Scripta Mathematica, 1955.
  • Prichett, G. D.; Ludington, A. L.; Lapenta, J. F. — "The determination of all decadic Kaprekar constants", Fibonacci Quarterly, 19:45–52, 1981.
  • Nishiyama, Yutaka — "Mysterious number 6174", Plus Magazine, 2006. plus.maths.org
  • Kay, Anthony; Downes-Ward, Katrina — "Fixed Points and Cycles of the Kaprekar Transformation", Journal of Integer Sequences, vol. 25, 2022.
  • Weisstein, Eric W. — "Kaprekar Routine" on Wolfram MathWorld. mathworld.wolfram.com
  • OEIS A099009 — Fixed points of the Kaprekar mapping. oeis.org/A099009

By Vincenzo Caserta — passionate about everything that catches his attention. For more insights into curious mathematics, wait until he gets intrigued by something else. 😂 In the meantime, visit the other pages of the blog where you will find deep dives into JD Edwards, technology, and who knows what else.