A magic square calculator makes a magic square of any order from 3 to 15, in which every row, every column and both diagonals add up to the same number, and it also checks a square that you type in. It gives the magic constant, the kind of order and the square itself. Enter the order and press the button. The constant and the classes follow the Wikipedia page on magic squares, and the work is done in your browser.
How to use the magic square calculator
- Choose to make a square or to check one.
- Enter the order n, or type the rows of your square.
- Press Calculate.
The magic constant
The page states that every normal magic square, one that uses the numbers 1 to n² once each, has a constant that depends only on the order: M = n(n² + 1)/2. The reason is simple. The numbers 1 to n² add up to n²(n² + 1)/2, and the square has n rows with the same sum, so each row sums to n(n² + 1)/2. The page lists the constants for orders 3 to 8 as 15, 34, 65, 111, 175 and 260. For an order 5 square, M is 5 × 26 / 2, which is 65. The calculator shows the constant and the total of all the numbers.
Odd, doubly even and singly even orders
The page sorts the orders into three classes. An order is odd if n is odd, doubly even, also called evenly even, if n is a multiple of 4, and singly even, or oddly even, for any other even n. The class matters because each needs a different method. The calculator uses the Siamese method, which the page names as the continuous method of De la Loubère, for odd orders. For multiples of 4 it fills the grid in order and then swaps certain cells with their complements. For singly even orders it uses Strachey's method, one of the methods named on the page, which builds four odd squares and swaps some columns between them.
The 3 × 3 square
The page shows the order 3 square with rows 4 9 2, 3 5 7 and 8 1 6 and a magic sum of 15. The calculator gives the equivalent square with rows 8 1 6, 3 5 7 and 4 9 2, which is the same square turned upside down. Every row, column and diagonal adds up to 15. The order 3 square is unique, apart from rotations and reflections. For larger orders the number of squares grows quickly, and the calculator gives one of them.
Checking your own square
To check a square, type its rows. The calculator adds each row, each column and the two diagonals, and compares them. If they are all equal, it is a magic square. If it also uses each number from 1 to n² once, it is a normal magic square. A square with the same sum in every line but with repeated numbers, such as a grid of all tens, is magic but not normal. If just one number is wrong, such as a swapped 6 and 1 in the 3 × 3 square, the sums that include the wrong cells differ, and you can see which lines fail.
Orders that are not covered
There is no magic square of order 2, which is why the calculator starts at 3. Orders above 15 are not offered here, since the output would be too wide to read comfortably, but the same methods work for any order above 2. In practice, magic squares are found in puzzles, in art and in recreational mathematics, and the calculator makes it easy to build one for a game or a lesson.
How the Siamese method works
For an odd order, start by putting 1 in the middle of the top row. Then move one cell up and one cell to the right for each next number, wrapping round to the opposite edge when you leave the grid. If the cell you reach is already filled, put the next number directly below the last one instead. For order 5, this gives rows 17 24 1 8 15, then 23 5 7 14 16, 4 6 13 20 22, 10 12 19 21 3 and 11 18 25 2 9, and every line adds up to 65. The calculator uses this method for the odd orders.
An order 4 example
For order 4, the calculator gives rows 16 2 3 13, 5 11 10 8, 9 7 6 12 and 4 14 15 1, and every line adds up to 34. The method writes the numbers 1 to 16 in order and then replaces the numbers on the two diagonals of each 4 by 4 block with their complements, 17 minus the number. The order 6 square, with a constant of 111, is built by Strachey's method from four order 3 squares, with a few columns swapped.
Extra properties
Some magic squares have more properties than the basic ones. In a pandiagonal square, the broken diagonals also add up to the magic constant. In an associative square, every pair of numbers opposite the center adds up to n² + 1. The 3 × 3 square above is associative: 8 and 2, 1 and 9, 6 and 4, and 3 and 7 each add up to 10. The calculator checks only the rows, columns and the two main diagonals, which is the usual definition of a magic square.
Common mistakes
- Forgetting a diagonal. A magic square needs both diagonals to match.
- Using the wrong constant. It is n(n² + 1)/2, not n² + 1.
- Repeating numbers. A normal square uses each number once.
- Trying order 2. It does not exist.
- Expecting one unique square. There are many for each order above 3.
What next
Use this often? Add Magic Square to your Home screen.
Frequently asked questions
What is a magic square calculator?
A tool that builds a magic square of a given order and checks whether a square has equal sums in every row, column and diagonal.
What is the magic constant?
M = n(n² + 1)/2. It is 15 for order 3, 34 for order 4 and 65 for order 5.
What are the kinds of order?
Odd (n odd), doubly even (n a multiple of 4) and singly even (any other even n). Each needs its own construction.
Is there a magic square of order 2?
No. The smallest normal magic square has order 3.
What is the 3 × 3 magic square?
Rows 8 1 6, 3 5 7 and 4 9 2, with every line adding up to 15. Rotations and reflections are also magic squares.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.