How to Solve a Magic Square, From the Last Gap to Crossing Lines
A magic square is one of the oldest number puzzles there is. Fill the grid with the numbers from 1 up, each one once, so that every row, every column and both long diagonals add up to the same total. On this page you get some numbers to start, and logic places the rest. Every puzzle has exactly one answer, and each level asks for a named technique, which this guide teaches in order.
📏 The Rules and the Magic Number
A 3 × 3 square uses 1 to 9, a 4 × 4 uses 1 to 16 and a 5 × 5 uses 1 to 25. Every number appears exactly once in the whole square, and each of the lines (the rows, the columns and the two corner-to-corner diagonals) adds up to the magic number: 15, 34 or 65.
Those totals aren't arbitrary. The numbers 1 to 9 add up to 45, and three rows share that equally, so each row must make 15. The same sum gives 136 ÷ 4 = 34 and 325 ÷ 5 = 65. As a formula, it is N × (N² + 1) ÷ 2. On the board, each line's running total sits at its end: green with a tick when it is right, red when it has gone over.
✏️ Easy: Find the Last Gap
Look for a line with exactly one empty square. Whatever the line is missing goes there. If a 4 × 4 row reads 16, 3, ?, 13, it adds to 32 so far, so the gap is 34 − 32 = 2. Fill it, and the column and diagonal through that square are one number closer to their own last gap.
That one move finishes every Easy puzzle on this page, and the generator checks it before you see the board. Easy gives you 3 of the 9 numbers on a 3 × 3, 8 of the 16 on a 4 × 4 and 14 or 15 of the 25 on a 5 × 5. On the 5 × 5 the arithmetic is the real workout: four numbers up to 25 to add in your head before you subtract from 65.
👯 Medium: Pairs That Fill Two Gaps
Medium gives fewer numbers, and the last-gap move alone stalls with most of the board still empty (about 6 squares of a 3 × 3, 9 of a 4 × 4 and 13 of a 5 × 5). The next idea is a line with two gaps. Work out what the two must add up to, then list the unused numbers that make that total in pairs.
Say a 4 × 4 bottom row reads 4, ?, ?, 1. The gaps need 34 − 5 = 29 between them. If the numbers still unused are 6, 7, 11, 14 and 15, only one pair makes 29: 14 and 15. The columns through them decide which goes where. Two more moves go with it: a number that has only one square left where it fits goes there, and a square with only one number left takes it.
⭐ Why the Middle of a 3 × 3 Is Always 5
Four lines pass through the middle square: the middle row, the middle column and both diagonals. Together they add to 4 × 15 = 60. Between them they cover all nine squares once, which is 45, and the middle square three extra times. So 60 = 45 + 3 × middle, and the middle is 5. Every other number then pairs across the middle to make 10: 1 with 9, 2 with 8, 3 with 7 and 4 with 6.
Push the argument one step further and the even numbers have to sit in the corners, which leaves the odd ones on the edges. The surprise is that this pins everything down: there is only one 3 × 3 magic square, turned and flipped eight ways. Our generator produced all eight and nothing else. That makes the 3 × 3 the size for learning the moves. A 3 × 3 Hard starts from just two numbers, and in a test of 200 of them, knowing the middle is 5 plus the pairs move finished every one.
✖️ Hard: Where Two Lines Cross
Hard on the bigger squares needs a move that no single line can give you. Any row and any column meet in exactly one square, and both add up to the magic number. Take the crossing square out of each, and what is left of the row adds up to the same as what is left of the column. You don't need to know the crossing square to use this.
It matters most when each line has one more gap. Then the two gaps differ by a fixed amount, and often only one pair of unused numbers is that far apart. The same rule works for a row or column against a diagonal, and for the two diagonals of a 5 × 5, which cross in the middle.
🔲 The 4 × 4 Corners Rule, and Ranges
Every 4 × 4 magic square hides a bonus: the four corners add up to 34, and so do the middle four squares. Here's why. The top row, bottom row and the two outside columns add to 4 × 34 = 136. That is the whole square (also 136) with the corners counted twice and the middle four left out, so the corners and the middle four add to the same amount. The two diagonals hold exactly those eight squares and make 68, so each group is 34. In 117 of 200 Hard 4 × 4 puzzles, the corners rule and ranges were enough without crossing lines.
Ranges are the last tool. When a line has three or more gaps, ask how big or small the others could possibly be. A 5 × 5 row holding 3 and 4 needs 58 from its other three squares. If the biggest unused numbers are 25, 21 and 17, any two of the gaps can make at most 25 + 21 = 46, so each gap needs at least 58 − 46 = 12. That rules out every unused number below 12 for all three squares at once. About 3 in 10 Hard 5 × 5 puzzles (61 of 200) fall to ranges alone; the rest need ranges and crossing lines together.
❌ Common Mistakes
- Forgetting the diagonals. A square whose rows and columns all make the total but whose diagonals don't is a semi-magic square, and it doesn't count. Their totals sit in the corners of the board: ↙ at the top right, ↘ at the bottom right.
- Assuming the middle of a 5 × 5 is 13. The 3 × 3 rule does not carry over. In 300 of our 5 × 5 squares, 13 was in the middle only 19 times, and every number from 1 to 25 turned up there at least once.
- Guessing and checking. It works on a 3 × 3, but there are 275,305,224 different 5 × 5 magic squares. Pairs and ranges find yours; trial and error won't.
- Hunting for a 2 × 2. There isn't one. With four squares, the top row and the left column share a corner and must make the same total, so the other two numbers would have to be equal.
📊 What the Sizes and Levels Mean Here
Every level is a technique, checked in both directions before a puzzle is published: our solver has to finish it with that level's moves, and it has to fail with the level below. Because each move is a forced step, a puzzle the solver finishes has only one answer. A separate brute-force search over every possible filling confirmed exactly one answer for all 900 puzzles in our test run.
| Level | What it needs | Numbers given (3 × 3 / 4 × 4 / 5 × 5) |
|---|---|---|
| Easy 😊 | The last gap only | 3 / 8 / 14–15 |
| Medium 🤔 | + pairs, and a number with one place left | 2–3 / 5–7 / 10–13 |
| Hard 🧠 | + ranges and lines combined (the middle 5, the corners rule, crossing lines) | 2 / 4–6 / 9–12 |
Measured over 100 puzzles of each size and level. When Hard is checked, the pairs solver stalls with about 6, 11 and 12 squares still empty.
Hard doesn't mean far fewer numbers: a Hard 5 × 5 shows about 10, against Medium's 11. It means different numbers, chosen so that pairs alone can't break in.
🎮 How to Play on This Page
Click an empty square to open a keypad beside it; numbers already in the square are grayed out. On a phone, tap a square and then a number in the tray under the board. On a keyboard, the arrow keys move, digits type (press 1 then 2 quickly for 12), and Backspace clears. Hover over a line's total to light up its squares.
Hint first takes out any number that is in the wrong place. Otherwise it fills the next square in the order our solver worked them out, and says which rule did it, such as "It's the last gap in column 3." Solution shows the finished square.
📜 Where Magic Squares Come From
The 3 × 3 is the Lo Shu square of Chinese legend, said to have appeared on the back of a turtle climbing out of the river Luo. It is first written down clearly in a Chinese book from the first century AD. The square reached the Islamic world and then Europe, where Albrecht Dürer put a 4 × 4 into his 1514 engraving Melencolia I. Its bottom row reads 4, 15, 14, 1, with the year in the middle, and it obeys the corners rule above (16 + 13 + 4 + 1 = 34). In 1693 the French mathematician Bernard Frénicle de Bessy's work showing that there are exactly 880 different 4 × 4 magic squares was published, and in 1973 Richard Schroeppel used a computer to count the 5 × 5s.
🧒 For Younger Players and Classrooms
A 3 × 3 Easy is subtraction from 15 with a reward at the end, and the running totals catch a slip the moment a line goes over. The 4 × 4 and 5 × 5 turn into real mental-arithmetic practice, and the pairs move is number bonds in disguise. For a class, Print 6 puzzles + answers makes a worksheet of six fresh puzzles at the size and level you have chosen, with a name and date line and the answers on a second page. It's free, with no email and no signup. When the 3 × 3 feels easy, try a Medium 4 × 4 and go looking for pairs. ✨