Magic square generator and checker

A magic square fills a grid with numbers so that every row, column and diagonal adds up to the same sum. Here you can generate one from 3×3 to 15×15 or check your own.

Example: What would you like to do: Generate a square · Size n 3 · Variant 1 · Smallest number 1 · Step 1 → Result: 3 × 3: magic constant 15. Source: Wikipedia – Magisches Quadrat (magische Konstante, Siamesische Methode, Komplementmethode, Strachey-Methode). Updated: .

n × n cells, 3 to 15
1 to 8: rotations and reflections
default 1; negative or 0 also work
gap between the numbers, default 1
My ToolboxYour inputs are saved in this browser only.

Result

Result
3 × 3: magic constant 15
The square
123
816
357
492
Sums
ItemValue
Every row15
Every column15
Both diagonals15
Sum of all numbers45
Range of numbers1 … 9
Odd order: built with the Siamese method (De la Loubère).

How it is calculated

The magic constant of a square of order n with the numbers 1 to n² is n · (n² + 1) / 2: 15 for 3×3, 34 for 4×4, 65 for 5×5.

How the square is built

For odd orders the Siamese method puts 1 above the centre and moves diagonally up and to the right, dropping one row down when a cell is taken. For orders divisible by 4 the numbers are written row by row and those on the diagonals of the 4×4 blocks are replaced by their complement n² + 1 − x. For order 4k + 2, Strachey’s method joins four sub-squares and swaps selected columns.

Variants and your own numbers

Rotations and reflections give up to 8 variants; the 3×3 square is unique apart from these symmetries. With a start number and step, 1, 2, 3 … can become 10, 12, 14 …, and the constant adapts: n · a + d · n · (n² − 1) / 2.

Frequently asked questions

How do you calculate the magic number of a magic square?

n · (n² + 1) / 2. For 3×3 that is 3 · 10 / 2 = 15, for 4×4 it is 4 · 17 / 2 = 34.

How do you solve a 3×3 magic square?

Put 5 in the centre, even numbers in the corners and odd numbers on the edges: 8 1 6 / 3 5 7 / 4 9 2. All other solutions are rotations or reflections.

What is a semi-magic square?

A square in which all rows and columns have the same sum, but the diagonals do not.

Sources and legal basis

As of: · Editorial policy

Related tools