Magic Squares: How They Work and How to Solve One
Number Challenges guide · 5 min read
A magic square is a grid of numbers where every row, every column, and both long diagonals add up to the same total. They've fascinated people for thousands of years, turning up in ancient Chinese legend, Renaissance art, and modern puzzle books. Behind the mystery is some neat, learnable mathematics: there's a formula for the target sum and a simple method for building one from scratch. This guide explains what magic squares are, the magic constant, a worked 3×3 example, and how to both construct and solve them, a classic addition to any number challenge toolkit.
What is a magic square?
A magic square is an n×n grid filled with distinct whole numbers, usually 1 through n², arranged so that the numbers in every row, every column, and both main diagonals all add up to the same value. That shared total is called the magic constant (or magic sum). The size n is the square's "order", a 3×3 square is order 3, a 4×4 is order 4, and so on.
The magic constant
You can work out the target sum before placing a single number. For a normal magic square using the numbers 1 to n², the magic constant is:
M = n × (n² + 1) ÷ 2
- For a 3×3 square (n = 3): M = 3 × (9 + 1) ÷ 2 = 15.
- For a 4×4 square (n = 4): M = 4 × (16 + 1) ÷ 2 = 34.
- For a 5×5 square (n = 5): M = 5 × (25 + 1) ÷ 2 = 65.
Knowing the magic constant is the single most useful fact for solving magic-square puzzles, because it tells you exactly what every line must sum to.
A worked 3×3 example
The most famous magic square is the order-3 Lo Shu square:
2 7 6
9 5 1
4 3 8
Check it against the magic constant of 15:
- Rows: 2 + 7 + 6 = 15, 9 + 5 + 1 = 15, 4 + 3 + 8 = 15.
- Columns: 2 + 9 + 4 = 15, 7 + 5 + 3 = 15, 6 + 1 + 8 = 15.
- Diagonals: 2 + 5 + 8 = 15, 6 + 5 + 4 = 15.
Every line sums to 15, and the numbers 1 through 9 each appear exactly once. Notice that 5, the middle value, sits in the centre, that's not a coincidence; in any 3×3 magic square the centre cell must hold the middle number.
How to build an odd magic square: the Siamese method
For any odd-order square (3×3, 5×5, 7×7), there's an elegant construction called the Siamese method:
- Place 1 in the middle cell of the top row.
- Move diagonally up and to the right to place the next number. If that takes you off the top, wrap to the bottom of that column; if it takes you off the right, wrap to the left of that row.
- If the cell you land on is already filled, drop straight down one cell instead and place the number there.
- Continue until all cells are filled.
Follow those rules and you'll produce a valid magic square every time. It's a satisfying little algorithm, and trying it on a 3×3 or 5×5 grid is the quickest way to understand how these squares hang together.
How to solve a partial magic square
In puzzles, you're usually given a magic square with some cells missing and asked to fill them in. The method is straightforward once you know the magic constant:
- Find the magic constant. Either it's given, or you compute M = n(n² + 1)/2.
- Look for the most-filled line. A row, column, or diagonal with only one blank is solved instantly: the blank equals the magic constant minus the numbers already there.
- Cascade. Each cell you fill helps complete the lines it sits in, so a single deduction often unlocks the next, exactly like solving a number theory puzzle by elimination.
- Check every line at the end. A correct solution makes every row, column, and diagonal hit the magic constant.
A little history
Magic squares are ancient. The Lo Shu square appears in Chinese legend, said to have been seen on the shell of a turtle emerging from a river. They spread across cultures as objects of mathematical and even mystical interest. The German artist Albrecht Dürer famously hid a 4×4 magic square in his 1514 engraving Melencolia I, arranging it so the two middle cells of the bottom row read "15 14", the year the work was made.
Magic squares sit at a lovely intersection of arithmetic, logic, and history. Learn the magic constant formula and the Siamese method, and you can both build and solve them with confidence. Put the skill to use on a number challenge and see how the sums fall into place.
Frequently asked questions
What is a magic square?
A magic square is a square grid filled with different numbers, usually 1 to n², arranged so that every row, every column, and both main diagonals add up to the same total, called the magic constant. The most famous is the 3×3 Lo Shu square, where every line sums to 15.
What is the magic constant?
The magic constant is the total that every row, column, and diagonal of a magic square must equal. For a normal n×n magic square using the numbers 1 to n², it equals n × (n² + 1) ÷ 2, which gives 15 for a 3×3 square, 34 for a 4×4, and 65 for a 5×5.
How do you solve a 3×3 magic square?
Use the magic constant of 15. Place the middle number (5) in the centre, then fill any row, column, or diagonal that has a single blank by subtracting the known numbers from 15. Each cell you place helps complete its lines, so the rest follows by elimination.
How do you make a magic square?
For odd-order squares, use the Siamese method: place 1 in the middle of the top row, then keep moving diagonally up-right to place each next number, wrapping around the edges, and dropping straight down whenever the target cell is already filled. This produces a valid magic square for any odd size.