Concept Recreational Mathematics ✓ Live

Magic Square

A magic square is a grid of distinct numbers arranged so that every row, every column, and both main diagonals all add up to exactly the same total. Known and studied across Chinese, Indian, Islamic, and European cultures for over 2,000 years, magic squares connect recreational puzzle-solving to serious mathematics in combinatorics, algebra, and even statistical experiment design.

Every row, every column, every diagonal — the same

Look at this 3×3 grid of the numbers 1 through 9:

4   9   2
3   5   7
8   1   6

Add up any row: 4+9+2=15, 3+5+7=15, 8+1+6=15. Any column: 4+3+8=15, 9+5+1=15, 2+7+6=15. Both diagonals: 4+5+6=15, 2+5+8=15. Every single line adds up to exactly 15. That's a magic square.

🧩 The oldest known example: This exact 3×3 square, called the Lo Shu square, appears in Chinese legend dating back over 2,000 years, said to have been seen on the back of a mystical turtle emerging from the Luo River.

Found across civilisations

Magic squares independently fascinated mathematicians across many cultures: China (Lo Shu legend, and later systematic study), India (appearing in Jain temple inscriptions and later mathematical texts), the Islamic world (extensive systematic study during the medieval period, including larger and more elaborate squares), and Europe (notably a famous 4×4 magic square appearing in Albrecht Dürer's 1514 engraving Melencolia I, which cleverly encodes the year 1514 in its bottom row).

Why "magic"?

The name reflects the squares' historical association with numerology, astrology, and even alleged magical or talismanic properties in several of these cultures — a magic square was sometimes believed to carry protective or fortunate properties when inscribed on an amulet, though this is a matter of cultural and historical belief rather than mathematical fact.

Construction methods and the magic constant

The magic constant

For an n×n magic square using the numbers 1 through n², the common sum (the "magic constant") is always:

M = n(n² + 1) / 2

For n=3: M = 3(10)/2 = 15, matching the Lo Shu square above. For n=4: M = 4(17)/2 = 34, matching Dürer's square.

The Siamese method (for odd-order squares)

For odd n (3, 5, 7, ...), a simple algorithm (sometimes called the Siamese method, popularised in Europe by Simon de la Loubère in 1693 after observing it in Siam/Thailand) constructs a magic square: place 1 in the middle of the top row; for each subsequent number, move diagonally up-and-right, wrapping around the edges of the grid, and if that cell is already filled, instead move straight down one row. This deceptively simple procedure always produces a valid magic square.

Doubly even and singly even squares

Different, more intricate construction algorithms are needed for "doubly even" orders (divisible by 4, like 4, 8, 12) and "singly even" orders (divisible by 2 but not 4, like 6, 10, 14) — the singly even case (notably including the historically important 6×6 case) is generally considered the most technically awkward to construct systematically, and historically took longer for mathematicians to fully resolve with a clean general method.

Dürer's 1514 square

16   3   2   13
5   10   11   8
9   6   7   12
4   15   14   1

Beyond the standard rows, columns, and diagonals, this particular square has numerous additional "magic" properties — for instance, the four corner numbers sum to 34, as does each of the four central 2×2 sub-squares — reflecting an extraordinary degree of mathematical craftsmanship deliberately built into the design.

Enumeration, generalisations, and modern connections

Counting magic squares

There is essentially only 1 distinct 3×3 magic square (up to the 8 trivial symmetries of rotation and reflection — all rotations/reflections of the Lo Shu square). For 4×4 squares, there are 880 essentially distinct magic squares. For 5×5, there are 275,305,224 — and the number of distinct magic squares grows extremely rapidly, making brute-force complete enumeration computationally infeasible for larger orders using current methods.

Ramanujan and magic squares

Srinivasa Ramanujan devised methods for constructing magic squares that additionally encoded a specific chosen date (for example, his own birth date) within the top row — an elegant, mathematically sophisticated party trick that also demonstrates the surprisingly rich underlying combinatorial flexibility available in valid magic-square constructions.

Latin squares and connection to experimental design

Magic squares are closely related to Latin squares (grids where each symbol appears exactly once in each row and column, without the additional sum-based "magic" requirement). Latin squares have serious modern statistical applications in the design of controlled scientific experiments (developed extensively by Ronald Fisher in the 1920s–30s), allowing researchers to systematically and efficiently control for multiple confounding variables simultaneously — a good example of a recreational-mathematics-adjacent structure finding genuine, practical, real-world scientific application.

Generalisations

Mathematicians have studied numerous variations: magic cubes (the 3-dimensional analogue), multiplicative magic squares (where rows/columns/diagonals share a common product rather than sum), prime magic squares (using only prime numbers), and panmagic squares (also called "most-perfect" or "diabolic" squares, where in addition to the standard requirements, every "broken diagonal" — including diagonals that wrap around the grid's edges — also sums correctly to the magic constant).

📚 Sources

Tier 1 Andrews, W.S. (1917, Dover reprint 1960). Magic Squares and Cubes. Dover Publications. — Standard classical reference.
Tier 2 Pickover, C.A. (2002). The Zen of Magic Squares, Circles, and Stars. Princeton University Press.
Tier 2 Cammann, S. (1960). The evolution of magic squares in China. Journal of the American Oriental Society, 80(2), 116–124. — Historical origins.
Tier 3 Kanigel, R. (1991). The Man Who Knew Infinity. Scribner. (Ramanujan's magic square constructions.)

🔗 Related entries

Related structureLatin squares — statistical experiment design
Entry v1.0 · Added 2026-05-27 · Recreational Mathematics · Concept JSON Markdown Status