Home / Learn / Maths / Kaprekar magic squaresTool #L125 (formerly #1240)

Kaprekar's constant 6174 and a magic square maker: number play you can watch

Run Kaprekar's routine on any 4-digit number and watch it land on 6174 (or 495 for 3 digits), with a chart of how many steps every start needs. Then build 3 × 3, 4 × 4 and 5 × 5 magic squares one number at a time.

Keep it one tap away for everyday use.

Bookmark Kaprekar magic squares?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Pick a start
  2. Repeat
  3. Magic square
  4. Check
Nothing is uploadedWorks offline once open

Kaprekar's routine

Arrange the digits biggest first and smallest first, take the smaller from the bigger, and repeat. Keep zeros: 999 as a 4-digit number is 0999. The digits must not all be the same.

    Try this

    • Find a 4-digit start that needs the most steps to reach 6174. (The chart says 7 is the most.)
    • Try 2111. Why does keeping the zero in 0999 matter?
    • Build the 3 × 3 square one number at a time. When does the up-and-right move get blocked, and what happens then?
    • Change "Start with" and "steps of". Is the square still magic? What is the new constant?

    Check yourself

    Fresh questions every time. Nothing is saved.

    What it does

    Kaprekar’s routine. Take a 4-digit number whose digits are not all the same. Arrange its digits from biggest to smallest and from smallest to biggest, and take the smaller number from the bigger. Repeat with the answer. Whatever you start with, you reach 6174 in at most 7 steps, and then you are stuck: 7641 − 1467 = 6174. With 3 digits the same thing happens with 495. The page lists every step and charts how many steps each start needs.

    Magic squares. In a magic square every row, column and diagonal adds to the same number, the magic constant. The maker builds them one number at a time with a slider:

    • 3 × 3 and 5 × 5: the up-and-right method. Put 1 in the middle of the top row; move one up and one right (wrapping round the edges), or one down if taken.
    • 4 × 4: write 1 to 16 in order, then swap every number on the two diagonals for 17 minus it.

    Tap two cells to swap them and see the sums break.

    It fits Class 8 Mathematics, number play (number puzzles, magic squares and Kaprekar’s constant). For more digit tricks, try the divisibility tests machine; for more number properties, the number theory toolkit.

    How to use it

    1. Choose Kaprekar 6174 or Magic squares.
    2. Kaprekar: type a start number or press Random number. Switch to 3 digits for 495.
    3. Magic squares: pick a size, then slide k from 0 to watch the numbers go in. At the end, the sums appear (green when they match).
    4. Change Start with and Go up in steps of, or tap two cells to swap them.

    A worked example

    The page starts with 3524: 5432 − 2345 = 3087, then 8730 − 0378 = 8352, then 8532 − 2358 = 6174, so it takes 3 steps.

    The 3 × 3 square comes out as 8 1 6 / 3 5 7 / 4 9 2. The numbers 1 to 9 add to 45, shared by 3 rows, so each line adds to 15. For sizes 3, 4 and 5 the constant is 15, 34 and 65.

    Check yourself

    Five fresh questions on Kaprekar steps and magic constants. Type a number and press Check.

    FAQ

    Why must the digits not all be the same? 1111 − 1111 = 0, and the routine stays at 0.

    Is this from the NCERT book? It covers the same topic with fibub’s own pictures and examples. fibub is not part of NCERT.

    Where the numbers come from

    • Kaprekar's routine (D. R. Kaprekar, 1949), the Lo Shu square, the up-and-right (de la Loubère) method for odd magic squares and the diagonal method for 4 × 4 are standard recreational mathematics. Wording, pictures and examples are fibub's own.
    • Checked against a Python brute force over every start 0000 to 9999 (steps to 6174: 0:1, 1:383, 2:576, 3:2400, 4:1272, 5:1518, 6:1656, 7:2184) and 000 to 999 (steps to 495, at most 6); every square is checked for equal row, column and diagonal sums.

    Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

    Last updated 2026-11-10.

    Change log for Kaprekar magic squares

    1. Add #1240 Kaprekar magic squares Details on GitHub
    2. Add #1238 Polygon angles Details on GitHub

    Every change to fibub

    Related tools

    Number theory toolkit #T372 Test whether a huge number is prime, factorise it, find gcd and lcm with the extended Euclid table, work out modular powers and inverses, solve Chinese remainder systems, and expand continued fractions with their convergents. Exact whole-number arithmetic, in your browser. HCF and LCM #L72 Type two numbers and watch their prime factor trees grow. Shared primes land in the middle of a Venn picture to give the HCF; all of them give the LCM. Euclid's division steps and the HCF × LCM check are shown too. Divisibility tests #L124 Type any whole number and see the divisibility rules for 2 to 11 worked on its digits, with the true remainder alongside. A place value picture shows why the rules for 3, 9 and 11 work, plus digital roots and casting out nines. Quadratic explorer #L68 Slide a, b and c and watch the parabola move: vertex, roots and the discriminant update live, completing the square is drawn with tiles, and the middle term is split for you. With fresh practice questions. Pythagoras proof playground #L69 Drag a right triangle and watch the squares on its sides add up. Slide through four visual proofs (rearrangement, Bhaskara, similar triangles, Baudhayana) with your own side lengths, and list Pythagorean triples. Trig ratio explorer #L70 Drag the angle of a right triangle and see sin, cos and tan as ratios of its sides, with the exact values at 0°, 30°, 45°, 60° and 90°, the identities checked live, and the full unit circle for Class 11.