All games

Magic Square

9 left

Make every line add up the same. How to solve

Magic sum 15 · 0:00

How to play Magic Square

What is a magic square?

A magic square is a square grid filled with the numbers 1 to n² (where n is the number of squares along each side) so that the numbers in each row, each column and both main diagonals add up to the same number. That number is the magic sum, also called the magic constant. It is the total of 1 to n² shared equally among the n rows, which works out to n(n² + 1) ÷ 2.

SizeNumbersMagic sum
3×31–915
4×41–1634
5×51–2565
6×61–36111
7×71–49175

If rotations and reflections of the same square count as one, there is exactly 1 magic square of size 3×3, there are 880 of size 4×4, and about 275 million of size 5×5.

How to solve a magic square

Start with the magic sum (15 for 3×3). The center of a 3×3 is always the magic sum ÷ 3, which is 5 for 1 to 9. Then look for a line with only one empty square and subtract the numbers already in it from the magic sum. 4×4 and 5×5 work the same way, and for a line with two empty squares, think about which pairs of unused numbers make up the difference.

How to make a magic square

Odd sizes (3×3, 5×5, 7×7…)

  1. Put 1 in the middle of the top row.
  2. Put each new number one square up and one square to the right. If that takes you off the top, go to the bottom row; off the right, go to the left column (think of the top and bottom edges, and the left and right edges, as joined).
  3. If that square is already filled, put the number directly below the last one instead. Repeat until the grid is full. This works for every odd size.
816
357
492
3×3 (magic sum 15)
17241815
23571416
46132022
101219213
11182529
5×5 (magic sum 65), from 1 going up and to the right

This is known as the Siamese method, or de la Loubère’s method, after the French diplomat who brought it back from Siam (now Thailand) in the 17th century.

4×4

  1. Write 1 to 16 in order, left to right and top to bottom.
  2. Replace each of the 8 numbers on the two diagonals with 17 minus that number (1 becomes 16, 6 becomes 11, and so on). The result is a 4×4 magic square.
1234
5678
9101112
13141516
Write in order
162313
511108
97612
414151
Diagonals replaced (magic sum 34)

Sizes that are multiples of 4 (8×8, 12×12…) work the same way: write 1 to n² in order, divide the grid into 4×4 blocks, and replace the numbers on each block’s diagonals with n² + 1 minus the number (65 minus the number for 8×8). Even sizes that are not multiples of 4 (6×6, 10×10…) are harder and need another method, such as combining odd squares.

History of magic squares

The oldest known magic square is the Lo Shu, a 3×3 square from Chinese legend that is said to have appeared on the shell of a turtle rising from the Luo River. The German artist Albrecht Dürer put a 4×4 magic square in his 1514 engraving Melencolia I. The two middle numbers of its bottom row, 15 and 14, spell out the year. In Japan, mathematicians of the Edo period such as Seki Takakazu studied how to construct them.