Magic Square Generator

Build a magic square of any size from 3 to 12, or a fill-in-the-blanks puzzle with exactly one answer. Every square is verified line by line.

Magic square

How these are built

  • Every row, every column and both long diagonals add up to the same number, using each whole number from 1 to n² exactly once.
  • That total is not a choice — it is forced. The numbers 1 to n² add up to n²(n²+1)/2, and that has to be shared equally between n rows.
  • Which construction works depends only on n mod 4. Odd sizes, sizes divisible by four, and the awkward middle cases like 6 and 10 each need a different method — which is why many generators quietly stop at 5.
  • There is no 2 × 2 magic square, and not because nobody has found one. Four cells with every pair summing alike forces all four numbers to be equal.
  • A magic square stays magic when rotated or mirrored, so each size has eight versions of the same square. For 3 × 3 those eight are all the magic squares that exist.
  • Puzzles only ever have one right answer — every arrangement of the missing numbers is checked before the puzzle is offered.

How to use

  1. Pick a size and press Make one.
  2. Switch to puzzle mode for a grid with blanks to fill in.
  3. Press Print for a clean copy.

Frequently asked questions

Why is there no 2 × 2 magic square?

Not because nobody has found one — because it cannot exist. Four cells where every row, column and diagonal must share a total forces all four numbers to be equal, and a magic square has to use four different numbers.

Where does the magic constant come from?

It is forced, not chosen. The numbers 1 to n² add up to n²(n²+1)/2, and that total has to be shared equally between n rows — so the constant is n(n²+1)/2. For a 3 × 3 that is 15, and for a 4 × 4 it is 34.

How is a magic square actually built?

It depends only on the size modulo four. Odd sizes use the Siamese method — step up and to the right, drop down when blocked. Sizes divisible by four use a complement pattern. Sizes like 6 and 10 need the LUX method, which is fiddlier and is why many generators quietly stop at 5.

How many 3 × 3 magic squares are there?

Exactly eight, and they are all rotations and mirrors of the same one. This is not folklore — checking all 362,880 arrangements of 1 to 9 finds precisely those eight.

Do the puzzles always have one answer?

Yes. Every arrangement of the missing numbers is checked before a puzzle is offered, and a grid with more than one valid completion is thrown away and redrawn. If it cannot find a unique one at the number of blanks you asked for, it tells you rather than handing over an ambiguous grid.

Why does pressing Make one give a different-looking square?

Rotating or mirroring a magic square leaves it magic, so each size has eight versions of the same underlying square. It picks one at random so the output does not look identical every time.

🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.