GenerateRandomSearch

Magic Square Generator

A magic square uses every number from 1 to n² exactly once and makes every row, column and both diagonals sum to the same total. That total is not chosen — it is forced by the size, at n(n²+1)/2 — and every size except 2×2 has one. This builds them by the classical constructions rather than by searching, so it is instant at any size, and every square is verified line by line before you see it.

What this generator does

Constructs rather than searches. Sudoku and nonograms on this site are generated and then checked for a unique solution; a magic square needs no search at all, because there are classical methods that produce one directly for each class of size. The tool picks the right method — Siamese for odd orders, the complement method for multiples of four, and the LUX method for the rest — and then verifies the finished square line by line.

How to use this tool

  1. Choose a size from 3 to 10.
  2. Build the square.
  3. Check any row, column or diagonal — that is the point.

Understanding the controls

Size
3 to 10. Odd sizes use the Siamese method, sizes divisible by four use a complement pattern, and sizes that are even but not divisible by four use the LUX method. 2×2 is not offered because no 2×2 magic square exists.

Worked examples

3×3
Every line sums to 15.
4×4
Every line sums to 34.
5×5
Every line sums to 65.
6×6
Every line sums to 111 — the awkward case that needs the LUX method.

Common use cases

  • A classroom introduction to arithmetic patterns and proof
  • Setting a puzzle where the answer can be checked without a key
  • Demonstrating that the magic constant is forced rather than chosen
  • Making a printable arithmetic exercise at a chosen difficulty
  • Curiosity — the constructions themselves are the interesting part

How this generator works

Three constructions, chosen by size. The Siamese method walks diagonally up and right, dropping down when blocked. The complement method for doubly-even orders fills the grid in order and then replaces the numbers in a criss-cross pattern with their complements. Singly-even orders use Conway's LUX method: an odd magic square of half the size, with each cell expanded into a 2×2 block in one of three patterns, and one exchange in the middle row that fixes the diagonals. The finished square is then checked — every row, every column, both diagonals, and that it uses each of 1 to n² exactly once.

Randomness and fairness

Nothing here is random. These are constructions, not searches, so a given size always produces the same square. That is a property of the classical methods rather than a limitation of the tool.

For how randomness is produced across the whole site, see how Generate Random works.

Assumptions this tool makes

  • A magic square means the normal kind — the consecutive numbers 1 to n², each used once.

Limitations and good to know

  • There is no 2×2 magic square, so the smallest offered is 3×3.
  • Each size produces one square from its construction rather than a random choice among the many that exist — the same size always gives the same square.
  • Only the standard normal magic square is produced: the numbers 1 to n², with rows, columns and both diagonals. Panmagic and bimagic variants are not implemented.

Common mistakes

Trying to build a 2×2
None exists. Four numbers cannot make two rows, two columns and two diagonals all sum alike.
Choosing the magic constant first
You cannot. For a normal magic square it is fixed at n(n²+1)/2 by the size alone.

Practical tips

  • Ask students to check a square before telling them it works — verifying is the exercise.
  • The 6×6 case is worth showing to anyone who thinks the easy method generalises; it does not, which is why LUX exists.

Privacy and your data

Everything is computed in your browser from a single number. There is nothing to upload and nothing to store, and no settings are written into the page address. Analytics records only that the tool was used.

Frequently asked questions

Why is the magic constant always the same for a given size?
Because the numbers 1 to n² add up to n²(n²+1)/2, and that total is shared equally between n rows. Divide and you get n(n²+1)/2, with nothing left to choose.
Why is there no 2×2 magic square?
The constant would have to be 5, and the two diagonals plus the rows and columns impose contradictory requirements on four numbers. It is provably impossible rather than merely hard.
Why does the same size always give the same square?
Because these are constructions rather than searches. Many magic squares exist at each size; the classical methods produce one specific example directly, which is what makes them instant.