🧮
🧮 Math & statistics

Magic Square Calculator (make an n×n magic square, any order from 3)

Results update as you type.

Your numbers

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.

Magic square4 × 4 magic square, every line 3416231351110897612414151row 116+2+3+13 = 34diagonal16+11+6+1 = 34S = 4 × 17 ÷ 234gold = diagonal cells (method flips these)
Numbers on the diagonals are replaced by 17 − n; that makes all 10 lines sum to 34.

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)

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.

  1. Magic constant S = 4 × (16 + 1) ÷ 2 = 34; numbers used 1, 2, …, 16; sum of all entries 136.
  2. Construction method: Diagonal method, doubly even order.
  3. Magic square, row by row: 16 2 3 13 | 5 11 10 8 | 9 7 6 12 | 4 14 15 1.
  4. Check: for example 16 + 2 + 3 + 13 = 34 and 16 + 11 + 6 + 1 = 34; all 10 lines add up to 34.
  5. Centre value — (only odd orders have a single centre cell).
How Magic constant (sum of every line) changes with Step between consecutive numbersHow Magic constant changes with Step bet…0204060800.250.50.7511.251.52Example: 34Step between consecutive numbers
Each point is the calculator re-run with only “Step between consecutive numbers” changed; the gold point is the default example. Change the inputs above and this chart follows your numbers.
Step between consecutive numbersMagic constant (sum of every line)
0.2511.5
0.519
0.7526.5
134
1.2541.5
1.549
264

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

Keep in mind: Magic squares are recreational mathematics. Squares with extra properties (such as panmagic squares) need other constructions.

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

Checked 9 Nov 2026. Encyclopedia of Mathematics (EMS / Springer), “Magic square” (n × n array of 1 … n² with equal row, column and diagonal sums; magic constant s = n(n² + 1)/2). Weisstein, E. W., “Magic Square”, Wolfram MathWorld (Siamese / de la Loubère method for odd orders; diagonal method for doubly even orders; J. H. Conway’s LUX method for singly even orders; no magic square of order 2).

🧮 All math & statistics tools →🌍 Calculators by country →