Magic square generator and guide

Choose an order from 3 to 15 to build a magic square and see its magic constant. Every row, column and diagonal is added up so you can check it.

Last updated · Method and sources below

Magic square generator

A whole number from 3 to 15.

How this is calculated

A magic square is an n × n grid of the distinct numbers 1 to n² in which every row, every column and both main diagonals add up to the same sum, called the magic constant. For order n the constant is n(n² + 1) / 2, so every 3 × 3 magic square adds up to 15.

The magic constant is the total of 1 to n², shared equally between n rows:

M = n(n² + 1) / 2

For n = 5 that is 5 × 26 / 2 = 65. For n = 3 it is 3 × 10 / 2 = 15. The constant is always a whole number for the orders this page builds. The magic constant formula guide has the proof.

The grid is built by one of three standard methods, chosen by the order. The same order always gives the same square, so the result can be repeated.

The generator supports orders 3 to 15 and builds normal magic squares only: the numbers 1 to n², each used once. After building a square, the page adds up all 2n + 2 lines (n rows, n columns and 2 diagonals) and lists each one so you can check the result by eye.

Many other magic squares exist for most orders. This page shows one square per order, not a catalogue. To fill in a grid you have started yourself, use the magic square solver.

Sources

  1. Weisstein, Eric W. “Magic Square.” MathWorld, A Wolfram Resource. mathworld.wolfram.com/MagicSquare.html (constant formula, Siamese and LUX methods).
  2. “Magic square.” Wikipedia. en.wikipedia.org/wiki/Magic_square (methods for odd, doubly even and singly even orders; no order-2 square).

A worked 3 × 3 example

3×3 magic square, constant 15
Column 1Column 2Column 3Diagonal ↗ sum ↗ 15
Row 1816Row 1 sum 15
Row 2357Row 2 sum 15
Row 3492Row 3 sum 15
Column sumsColumn 1 sum 15Column 2 sum 15Column 3 sum 15Diagonal ↘ sum ↘ 15

The grey figures are the sums of each row (right), each column (bottom) and the two diagonals (corners). Every one is 15.

Check it by hand: rows 8 + 1 + 6, 3 + 5 + 7 and 4 + 9 + 2 each make 15; columns 8 + 3 + 4, 1 + 5 + 9 and 6 + 7 + 2 each make 15; diagonals 8 + 5 + 2 and 6 + 5 + 4 each make 15. This is the square the Siamese method gives for n = 3. For why its centre must be 5, see the 3 × 3 magic square guide.

Why there is no 2 × 2 magic square

With the numbers 1 to 4 the constant would be 2 × 5 / 2 = 5, so a + b = 5 and a + c = 5 for the top row and left column. That forces b = c, so a number would have to repeat, which a normal magic square forbids. The same argument rules out every arrangement of 1 to 4.

Where to go next

Tools

Guides

To build a square by hand, see how to make a magic square.