Magic Square Generator

Verified magic squares of any order from 3 to 30.

About this tool

Choose the size n and the starting number. The magic square appears with its magic constant and a check that every row, column and diagonal adds up correctly. Cycle through its rotations and reflections, or copy it as tab-separated text.

How magic squares are built

A magic square of order n uses the numbers 1 to nΒ² once each so that every row, every column and both main diagonals have the same total, the magic constant n(nΒ² + 1) Γ· 2: 15 for 3 Γ— 3, 34 for 4 Γ— 4, 65 for 5 Γ— 5 and 111 for 6 Γ— 6. Different orders need different methods. Odd orders use the Siamese method described by Simon de la LoubΓ¨re in 1693: start in the top middle and move diagonally up and right, dropping down a cell when blocked. Doubly even orders (multiples of 4) fill the grid in order and swap the numbers on a diagonal pattern for their complements. Singly even orders (6, 10, 14…) are the hardest; this tool uses John Conway's LUX method. Every result is verified automatically. Add a constant to every cell, or start at a different number, and the square stays magic. The 4 Γ— 4 square in Albrecht DΓΌrer's 1514 engraving Melencolia I even shows the year in its bottom row. Honest limits: these constructions produce one family of squares; there are 880 different 4 Γ— 4 magic squares and about 275 million 5 Γ— 5. The sudoku puzzle and the maths worksheet generator are related.

Frequently asked questions

What is the magic constant for a 3x3 magic square?

15. In general it's n(nΒ² + 1) Γ· 2.

Is there a 2x2 magic square?

No. Order 2 is impossible with the numbers 1 to 4; every order from 3 upwards works.

How do you make an odd magic square?

Use the Siamese method: put 1 in the top middle, then move up and right, wrapping around, and drop down one cell when the target is taken.

How many 3x3 magic squares are there?

Just one, apart from its 8 rotations and reflections.

Is my data sent anywhere?

No. Everything is calculated in your browser, and nothing is stored or sent.