Understanding the magic square calculator — concept and principle
This calculator builds an n × n magic square for any order from 3, using the numbers of an arithmetic sequence (1, 2, 3, … by default). Every row, column and main diagonal adds up to the same magic constant, and the page checks all of them. Use it for puzzles, classroom activities and recreational mathematics.
How it is calculated
Magic constant for 1 … n²: S = n(n² + 1) ÷ 2 (15 for n = 3, 34 for n = 4, 65 for n = 5)
- Odd orders: the Siamese (de la Loubère) method.
- Doubly even orders (4, 8, 12, …): the diagonal method.
- Singly even orders (6, 10, …): Conway's LUX method.
- With a different first number or step, each entry is first + step × (k − 1), and the constant changes accordingly.
- Order 2 is impossible.
The principle
The numbers 1 to n² add up to n²(n² + 1) ÷ 2. Split evenly over n rows, each row must total n(n² + 1) ÷ 2, which fixes the magic constant. The construction methods place the numbers so that columns and diagonals balance too. In the diagonal method for order 4, numbers are written 1 to 16 in order, and those on the two main diagonals (and the matching cells in each 4 × 4 block) are replaced by 17 minus themselves, which balances every line.
Worked example
Default inputs: order 4, first number 1, step 1.
- Magic constant S = 4 × (16 + 1) ÷ 2 = 34; numbers used 1, 2, …, 16; sum of all entries 136.
- Construction method: Diagonal method, doubly even order.
- Magic square, row by row: 16 2 3 13 | 5 11 10 8 | 9 7 6 12 | 4 14 15 1.
- Check: for example 16 + 2 + 3 + 13 = 34 and 16 + 11 + 6 + 1 = 34; all 10 lines add up to 34.
- Centre value — (only odd orders have a single centre cell).
| Step between consecutive numbers | Magic constant (sum of every line) |
|---|---|
| 0.25 | 11.5 |
| 0.5 | 19 |
| 0.75 | 26.5 |
| 1 | 34 |
| 1.25 | 41.5 |
| 1.5 | 49 |
| 2 | 64 |
How to read the result
Many different magic squares exist for each order from 4 upward; the page shows one standard construction. Rotating or reflecting a square gives another valid one. For n = 3 there is essentially only one magic square, with 5 in the centre.
Common mistakes
- Using the wrong constant formula, such as n(n + 1) ÷ 2.
- Forgetting to check the two diagonals.
- Trying to build a 2 × 2 magic square.
- Applying the odd-order method to an even order.
Frequently asked questions
What is the magic constant of a 4 × 4 square?
34.
Why is there no 2 × 2 magic square?
With 1 to 4, two numbers in a row and a column would have to be equal, which is impossible.
What is the Siamese method?
A rule for odd orders: start in the middle of the top row and move up and right, dropping down when the cell is taken.
Sources: Encyclopedia of Mathematics (EMS / Springer), "Magic square" · E. W. Weisstein, "Magic Square", Wolfram MathWorld