Kaprekar’s Constant – Blog Posts
- 2025, Jan 26 – 6174 Kaprekar’s Constant
- 2025, Dec 31 – Massive 6174 Kaprekar’s Routine Database & Analysis
Kaprekar’s Constant
On January 15, 2025, a friend of mine told me about the magic number 6174, known as Kaprekar’s constant. It is arrived at from Kaprekar’s routine:
- Start with any 4-digit number, in base-10.
- Sort the digits from largest to smallest, and smallest to largest. Include the leading zeroes.
- Subtract one from the other.
- Repeat.
- Eventually, this reaches 6174.
- Any further iteration stays at 6174.
Let’s try 5183:
- 8531 – 1358 = 7173
- 7731 – 1377 = 6354
- 6543 – 3456 = 3087
- 8730 – 0378 = 8352
- 8532 – 2358 = 6174
- 7641 – 1467 = 6174 (it will repeatedly reproduce 6174 over and over)
One exception: All repdigit numbers — numbers made up of the same digit, such as 1111 or 5555 — reach 0000 in one iteration. The procedure calls to ignore such numbers, as they are trivial exceptions.
Let’s try repdigit 7777:
- 7777 – 7777 = 0000
- 0000 – 0000 = 0000 (repeats forever, and could be considered a second ending)
It takes at most 7 iterations for any 4-digit number to reach 6174.
Let’s try 1400:
- 4100 – 0014 = 4086 (iteration 1)
- 8640 – 0468 = 8172 (iteration 2)
- 8721 – 1278 = 7443 (iteration 3)
- 7443 – 3447 = 3996 (iteration 4)
- 9963 – 3699 = 6264 (iteration 5)
- 6642 – 2466 = 4176 (iteration 6)
- 7641 – 1467 = 6174 (iteration 7)
3 Digits = Similar Property
Is a similar outcome true for other digit lengths? Let’s try 3-digits.
Yes! All 3-digit numbers eventually reach 495 (again, except for repdigit numbers that all result in 000), which then repeatedly becomes 495 over and over again.
Let’s try 100:
- 100 – 001 = 099
- 990 – 099 = 891
- 981 – 189 = 792
- 972 – 279 = 693
- 963 – 369 = 594
- 954 – 459 = 495
3-digit and 4-digit are the only digit lengths with the property that, aside from the 9 repdigit numbers that result in all zeroes, all other numbers result in a single result, which itself repeats immediately.
2 Digits = New Property: Loop Cycles
Let’s look at 2-digit numbers. What new properties do they possess?
Again, all repdigit numbers (00, 11, 22, .. 99) result in zero — this is actually consistent for any digit length. (This makes 1-digit numbers boring, which I’ll ignore, as they all result in zero.)
The rest all result in the same loop of numbers, much like 6174 or 495, except they don’t settle into a single number (i.e. 6174 → 6174 → 6174 → etc.)! They instead settle in a loop:
- ⮎ 09 → 81 → 63 → 27 → 45 ⮌
All of the original 2-digit numbers end up at one of these 5 numbers, and then it cycles through them. This is interesting, since it means there are multiple ways one could count iterations.
Iteration Counts
Given any single number, you could determine the iteration count in 2 ways:
- Iterate until you see the First Repeat.
- Iterate until you Start the End Loop.
For example, using 79:
- 97 – 79 = 18
- 81 – 18 = 63 : This is the Start of the End Loop: ⮎ 09 → 81 → 63 → 27 → 45 ⮌
- 63 – 36 = 27
- 72 – 27 = 45
- 54 – 45 = 09
- 90 – 09 = 81
- 81 – 18 = 63 : This is the First Repeat of any result.
Stopping at the “Start of the End Loop” sounds like you are short-circuiting the calculations — and you are! So why do this? Because the standard practice for 6174 is to stop when you reach 6174, not when you see it again (on the very next iteration) since you know it’s coming up again right away (i.e. it has already “settled”). However, unless you already knew 6174 would repeat, you’d actually have to iterate once more to see… and for results that don’t settle to a single number, but create a loop of many numbers, you’d have no choice to continue iterating until you see the loop repeat.
Therefore I compute both.
Let’s take a look at the 4-digit numbers again:
- First Repeat: 7 iterations: 1400 → 4086 → 8172 → 7443 → 3996 → 6264 → 4176 → 6174 (loop start)
- Loop Start: 8 iterations: 1400 → 4086 → 8172 → 7443 → 3996 → 6264 → 4176 → 6174 → 6174 (repeat)
5-Digits = Multiple End Loops
Let’s go larger!
Aside from the repdigits all resulting in 0, we have 3 end loops:
- ⮎ 62964 → 71973 → 83952 → 74943 ⮌
- ⮎ 53955 → 59994 ⮌
- ⮎ 61974 → 82962 → 75933 → 63954 ⮌
Longest iteration counts:
- First Repeat: 10 iterations: 00001 → 09999 → 89991 → 80982 → 95931 → 85932 → 74943 → 62964 → 71973 → 83952 → 74943 (repeat)
- Loop Start: 6 iterations: 00001 → 09999 → 89991 → 80982 → 95931 → 85932 → 74943 (loop start)
You can see the difference of iteration counts depending on where you stop. The 74943 number is at the end of the first loop. I compute the loops by using the smallest number within the loop as the start, though this is arbitrary.
Leading Zeroes
In the above, you may be wondering why the number is written as 00001 instead if 10000.
Isn’t that a 1 digit number, not a 5 digit number?
A few notes:
- We always keep leading zeroes, used in the digit sorting.
- But we don’t count leading zeroes for only the very first number.
- However, any number with at least one non-zero digit can be reordered to have no leading zeroes. If we deduplicate all of these, we are essentially trying 00001 and 10000 as they are both the same, as soon as the algorithm starts (since the first step is to sort the digits).
- Therefore, the only starting number that we do not compute is one that doesn’t have at least one non-zero digit — the number that is all zeroes!
- Okay again: Why does my program report 00001? Couldn’t it just as simply show 10000? Yes, it could. The only reason it doesn’t is that it reports the smallest number found regardless of leading zeroes or not. It is really just arbitrary.
6-Digit Numbers
I’m sure you are dying to see what is in store. For end loops, we once again see some loops that are only 1 in length, similar to 6174 (4-digit) and 495 (3-digit).
- ⮎ 420876 → 851742 → 750843 → 840852 → 860832 → 862632 → 642654 ⮌
- ⮎ 631764 ⮌
- ⮎ 549945 ⮌
Longest iteration counts:
- First Repeat: 20 iterations: 000599 → 994401 → 979911 → 881712 → 774423 → 539955 → 639954 → 650844 → 820872 → 864432 → 629964 → 749943 → 652644 → 420876 → 851742 → 750843 → 840852 → 860832 → 862632 → 642654 → 420876 (repeat)
- Loop Start: 13 iterations: 000599 → 994401 → 979911 → 881712 → 774423 → 539955 → 639954 → 650844 → 820872 → 864432 → 629964 → 749943 → 652644 → 420876 (loop start)
Terminology
There are a few different terms that could / should be used:
- Fixed Point (Mathematics) = a value that does not change under a given transformation.
- Loop (Graph Theory) = a node that points back to itself.
- Cycle (Graph Theory) = a series of connected nodes that eventually lead back to the first.
- Kernel = “We call the number 6174 a kernel of this operation” — Yutaka Nishiyama, where “operation” means the iteration of “Kaprekar’s routine“, where “Kaprekar’s operation” is an alternate name for the procedure / algorithm.
Fixed Points
A fixed point in Mathematics is a value that does not change under a given transformation. Therefore, 6174 is a fixed point. It is otherwise known as a loop in Graph Theory or perhaps a Cycle of length 1.
In 5 days, on January 20, 2025, I calculated all fixed points for digit lengths from 1 to 32 digits in size. This exceeds the prior largest digit efforts that I am aware of (2005, Hirata, Yumi: calculated all fixed points up to 31-digits & examined their distribution: https://kyoai.repo.nii.ac.jp/record/21/files/2005-hirata.pdf).
Please see the results below.
This is only showing fixed points, even when there are other cycles (length 2 or greater). Thus, each of these numbers produce themselves after a single iteration = fixed points. (I did not include the trivial repdigit all-zeroes, which is present for each digit length.)
I have highlighted the digit lengths that have a single fixed point. However note that only 3-digit and 4-digit numbers all converge to this fixed point (except for all-zeroes), whereas 11-digit and 13-digit numbers have other longer cycles that are also reached.
Digit Sets and their Fixed points
- none
- none
- 495
- 6174
- none
- 631764, 549945
- none
- 97508421, 63317664
- 864197532, 554999445
- 9753086421, 9975084201, 6333176664
- 86431976532
- 975330866421, 555499994445, 997530864201, 999750842001, 633331766664
- 8643319766532
- 97533308666421, 97755108844221, 99753308664201, 99975308642001, 99997508420001, 63333317666664
- 864333197666532, 555549999944445
- 9775531088644221, 9977551088442201, 9753333086666421, 9975333086664201, 9997533086642001, 9999753086420001, 9999975084200001, 6333333176666664
- 98765420987543211, 86433331976666532
- 886644219977553312, 977553310886644221, 975333330866666421, 999775510884422001, 555554999999444445, 997755310886442201, 997533330866664201, 999753330866642001, 999975330866420001, 999997530864200001, 999999750842000001, 633333331766666664
- 9876543209876543211, 8643333319766666532, 9987654209875432101
- 88664432199776553312, 97755333108866644221, 99775533108866442201, 99997755108844220001, 99977553108864422001, 97775551108884442221, 97533333308666666421, 99753333308666664201, 99975333308666642001, 99997533308666420001, 99999753308664200001, 99999975308642000001, 99999997508420000001, 63333333317666666664
- 987654332098766543211, 864333333197666666532, 998765432098765432101, 555555499999994444445, 999876542098754321001
- 9775533331088666644221, 9777555311088864442221, 9753333333086666666421, 8866443321997766553312, 9997755331088664422001, 9999977551088442200001, 9999775531088644220001, 9977553331088666442201, 9977755511088844422201, 9975333333086666664201, 9997533333086666642001, 9999753333086666420001, 9999975333086664200001, 9999997533086642000001, 9999999753086420000001, 9999999975084200000001, 6333333333176666666664
- 98765433320987666543211, 98776554210988754432211, 87765443219997765543222, 99987654320987654321001, 86433333331976666666532, 99876543320987665432101, 99998765420987543210001
- 977755533110888664442221, 977553333310886666644221, 886644333219977666553312, 997755333310886666442201, 999977553310886644220001, 997775553110888644422201, 555555549999999944444445, 999999775510884422000001, 999997755310886442200001, 999775533310886664422001, 999777555110888444222001, 975333333330866666666421, 997533333330866666664201, 999753333330866666642001, 999975333330866666420001, 999997533330866664200001, 999999753330866642000001, 999999975330866420000001, 999999997530864200000001, 999999999750842000000001, 633333333331766666666664
- 9876543333209876666543211, 9877655432109887654432211, 9987765542109887544322101, 9999876543209876543210001, 9987654333209876665432101, 9998765433209876654321001, 9999987654209875432100001, 8643333333319766666666532
- 97775553331108886664442221, 98876654422099877554332111, 97755333333108866666644221, 99777555331108886644422201, 97777555511108888444422221, 88664433332199776666553312, 99977553333108866664422001, 99775533333108866666442201, 99997755333108866644220001, 99999775533108866442200001, 99977755531108886444222001, 99999977553108864422000001, 99999997755108844220000001, 99997775551108884442220001, 97533333333308666666666421, 99753333333308666666664201, 99975333333308666666642001, 99997533333308666666420001, 99999753333308666664200001, 99999975333308666642000001, 99999997533308666420000001, 99999999753308664200000001, 63333333333317666666666664, 99999999975308642000000001, 99999999997508420000000001
- 987654333332098766666543211, 987765543321098876654432211, 888666444221999777555333112, 998776554321098876544322101, 999877655421098875443221001, 999998765432098765432100001, 998765433332098766665432101, 999876543332098766654321001, 999987654332098766543210001, 999999876542098754321000001, 864333333333197666666666532, 555555554999999999444444445
- 9887665443220998776554332111, 9777555333311088866664442221, 9977755533311088866644422201, 9777755553111088886444422221, 9775533333331088666666644221, 9997775553311088866444222001, 9988766544220998775543321101, 8866443333321997766666553312, 9977775555111088884444222201, 9977553333331088666666442201, 9999775533331088666644220001, 9997755333331088666664422001, 9999977553331088666442200001, 9999997755331088664422000001, 9999777555311088864442220001, 9999999775531088644220000001, 9999999977551088442200000001, 9999977755511088844422200001, 9753333333333086666666666421, 9975333333333086666666664201, 9997533333333086666666642001, 9999753333333086666666420001, 9999975333333086666664200001, 9999997533333086666642000001, 9999999753333086666420000001, 9999999975333086664200000001, 9999999997533086642000000001, 6333333333333176666666666664, 9999999999753086420000000001, 9999999999975084200000000001
- 98765433333320987666666543211, 88866644432219997776555333112, 98776554333210988766654432211, 98777655542110988875444322211, 99987765543210988765443221001, 99877655433210988766544322101, 99998776554210988754432210001, 99999987654320987654321000001, 99876543333320987666665432101, 99987654333320987666654321001, 99998765433320987666543210001, 99999876543320987665432100001, 99999998765420987543210000001, 86433333333331976666666666532
- 988766544332209987766554332111, 998876654432209987765543321101, 977775555331110888866444422221, 999777555333110888666444222001, 977755533333110888666664442221, 997775553333110888666644422201, 977553333333310886666666644221, 999977755533110888664442220001, 997777555531110888864444222201, 999887665442209987755433211001, 886644333333219977666666553312, 999777755551110888844442222001, 999775533333310886666664422001, 997755333333310886666666442201, 999997755333310886666442200001, 999977553333310886666644220001, 999999775533310886664422000001, 999999977553310886644220000001, 999997775553110888644422200001, 999999997755310886442200000001, 975333333333330866666666666421, 999999999775510884422000000001, 999999777555110888444222000001, 997533333333330866666666664201, 999753333333330866666666642001, 999975333333330866666666420001, 999997533333330866666664200001, 999999753333330866666642000001, 999999975333330866666420000001, 999999997533330866664200000001, 999999999753330866642000000001, 999999999975330866420000000001, 633333333333331766666666666664, 999999999997530864200000000001, 999999999999750842000000000001, 555555555499999999994444444445
- 9877655433332109887666654432211, 9876543333333209876666666543211, 9877765554321109888765444322211, 9999877655432109887654432210001, 9987765543332109887666544322101, 9998776554332109887665443221001, 9987776555421109888754443222101, 9999987765542109887544322100001, 8886664443322199977766555333112, 9999999876543209876543210000001, 9987654333333209876666665432101, 9998765433333209876666654321001, 9999876543333209876666543210001, 9999987654333209876665432100001, 9999998765433209876654321000001, 8643333333333319766666666666532, 9999999987654209875432100000001
- 98876654433322099877666554332111, 98877665544221099887755443322111, 97777555533311108888666444422221, 99988766544322099877655433211001, 99997775553331108886664442220001, 97755333333333108866666666644221, 99977755533331108886666444222001, 99777755553311108888664444222201, 97775553333331108886666664442221, 99887665443322099877665543321101, 99999777555331108886644422200001, 99977775555311108888644442222001, 99777555333331108886666644422201, 99998876654422099877554332110001, 88776654443221999977765554332212, 99997777555511108888444422220001, 99775533333333108866666666442201, 99997755333333108866666644220001, 99977553333333108866666664422001, 88664433333332199776666666553312, 99999977553333108866664422000001, 99999775533333108866666442200001, 97777755555111108888844444222221, 99999997755333108866644220000001, 99999999775533108866442200000001, 99999977755531108886444222000001, 99999999977553108864422000000001, 97533333333333308666666666666421, 99999999997755108844220000000001, 99753333333333308666666666664201, 99999997775551108884442220000001, 99975333333333308666666666642001, 99997533333333308666666666420001, 99999753333333308666666664200001, 99999975333333308666666642000001, 99999997533333308666666420000001, 99999999753333308666664200000001, 99999999975333308666642000000001, 99999999997533308666420000000001, 99999999999753308664200000000001, 63333333333333317666666666666664, 99999999999975308642000000000001, 99999999999997508420000000000001
See even more in my database:
Cycles
Showing all cycles, including those of length 1, including repdigits (that all end in zero).
The odd-numbered digit lengths produces a smaller set of resultant loops.
The even-numbered digit lengths produces a myriad of resultant loops.
I also compute the frequency of each end loop. I have an algorithm optimized to only check for “unique digit-sorted starting numbers”, therefore it will not compute both 1234 and 4321, since they are the same after being sorted. The counts are of these unique numbers, not of all possible numbers.
While I compute all digit lengths from 1 to 32, but I am limiting this report due to verbosity.
- 1-Digit Numbers
- 9× ⮎ 0 ⮌
- 2-Digit Numbers
- 45× ⮎ 09 → 81 → 63 → 27 → 45 ⮌
- 9× ⮎ 00 ⮌
- 3-Digit Numbers
- 210× ⮎ 495 ⮌
- 9× ⮎ 000 ⮌
- 4-Digit Numbers
- 705× ⮎ 6174 ⮌
- 9× ⮎ 0000 ⮌
- 5-Digit Numbers
- 1,004× ⮎ 62964 → 71973 → 83952 → 74943 ⮌
- 108× ⮎ 53955 → 59994 ⮌
- 880× ⮎ 61974 → 82962 → 75933 → 63954 ⮌
- 9× ⮎ 00000 ⮌
- 6-Digit Numbers
- 4,613× ⮎ 420876 → 851742 → 750843 → 840852 → 860832 → 862632 → 642654 ⮌
- 352× ⮎ 631764 ⮌
- 30× ⮎ 549945 ⮌
- 9× ⮎ 000000 ⮌
- 7-Digit Numbers
- 11,430× ⮎ 7509843 → 9529641 → 8719722 → 8649432 → 7519743 → 8429652 → 7619733 → 8439552 ⮌
- 9× ⮎ 0000000 ⮌
- 8-Digit Numbers
- 12,051× ⮎ 64308654 → 83208762 → 86526432 ⮌
- 11,628× ⮎ 43208766 → 85317642 → 75308643 → 84308652 → 86308632 → 86326632 → 64326654 ⮌
- 321× ⮎ 97508421 ⮌
- 300× ⮎ 63317664 ⮌
- 9× ⮎ 00000000 ⮌
- 9-Digit Numbers
- 46,192× ⮎ 753098643 → 954197541 → 883098612 → 976494321 → 874197522 → 865296432 → 763197633 → 844296552 → 762098733 → 964395531 → 863098632 → 965296431 → 873197622 → 865395432 ⮌
- 2,388× ⮎ 864197532 ⮌
- 30× ⮎ 554999445 ⮌
- 9× ⮎ 000000000 ⮌
- 10-Digit Numbers
- 13,110× ⮎ 6431088654 → 8732087622 → 8655264432 ⮌
- 21,583× ⮎ 4332087666 → 8533176642 → 7533086643 → 8433086652 → 8633086632 → 8633266632 → 6433266654 ⮌
- 38,938× ⮎ 6433086654 → 8332087662 → 8653266432 ⮌
- 5,718× ⮎ 9753086421 ⮌
- 3,582× ⮎ 9751088421 → 9775084221 → 9755084421 ⮌
- 9,004× ⮎ 6543086544 → 8321088762 → 8765264322 ⮌
- 169× ⮎ 9975084201 ⮌
- 264× ⮎ 6333176664 ⮌
- 9× ⮎ 0000000000 ⮌
See more in my database:
UPDATE: Further Calculations
Over the year 2025, I produced a ton of data on Kaprekar’s routine for all radix 2 through 255, and for all digit lengths 1 through to 100 (though not for every radix), limited by CPU efforts — running on two Alienware gaming laptops with 12-core and 32-cores for a couple of months).
See the efforts here:
- My new blog post:
- My database analysis / presentation:
- fixed points:
- cycles:
- max steps to reach a final number:
- summary:
Resources
- Numberphile video: I first heard about this from a good friend of mine on January 15, 2025, via a YouTube short that was made from this source video.
- Mysterious number 6174 – Yutaka Nishiyama
- Mathews: the Archive of Recreational Mathematics by Walter Schneider: Kaprekar Process (Internet Archive, 2007-05-14)
- Hirata, Yumi (2005): calculated all fixed points up to 31-digits & examined their distribution: https://kyoai.repo.nii.ac.jp/record/21/files/2005-hirata.pdf
- My blog posts:
- 6174 Kaprekar’s Constant — my initial findings (January 20, 2025)
- Massive 6174 Kaprekar’s Routine Database & Analysis — my latest findings (December 31, 2025)






Leave a Reply
You must be logged in to post a comment.