✨ Magic Square Puzzle Online

Fill the square so every row, column and diagonal adds up to the same number.

Numbers left (tap a square, then a number)

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.

💡 Once in the square, not once per line. Players arriving from Sudoku look for each number in every row. Here a number appears once in the whole grid, so a 7 in the top row is a 7 nowhere else. The tray under the board crosses numbers off as you use them, and the unused ones are your whole toolkit.

✏️ 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.

A 4 by 4 magic square part solved. Row 1 reads a gap, then 16, 9 and 2, its total shows 27, and a note beside it says 34 minus 27 equals 7.
Row 1 adds to 27 with one gap left, so the gap is 34 − 27 = 7. The square's column and diagonal light up too, ready for the next move.

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.

A 4 by 4 magic square with the two gaps in column 4 marked, a note saying they need 13, either 3 plus 10 or 4 plus 9, and the tray of unused numbers underneath.
Column 4 needs 13 from its two gaps: 3 + 10 or 4 + 9. The top gap is also in row 1, which needs 18 from its own two gaps, and only 4 has a free partner there (14). So the top is 4 and the bottom is 9.

⭐ 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.

The Lo Shu square: 5 in the middle, even numbers in the corners.

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.

A 4 by 4 magic square where row 1 and column 2 meet in an empty square. Each line has one more gap, marked, and a note gives the rest of row 1 as 9 plus a gap, the rest of column 2 as 17 plus a gap, and the unused numbers 3, 8, 9, 10, 11, 14 and 15.
Row 1 and column 2 meet in the empty square at the top. Leave it out, and 9 plus the row's other gap must equal 17 plus the column's, so the row's gap is 8 bigger. Only 11 and 3 are unused and 8 apart, so 11 ends row 1 and 3 goes in column 2. Either line on its own still allowed two pairs.
🧭 Stuck on a Hard? Look for a row and a column that cross in a gap and have one more gap each. Measured over 200 Hard 5 × 5 puzzles, 139 couldn't be finished without this move.

🔲 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

📊 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.

LevelWhat it needsNumbers given (3 × 3 / 4 × 4 / 5 × 5)
Easy 😊The last gap only3 / 8 / 14–15
Medium 🤔+ pairs, and a number with one place left2–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. ✨

Written and reviewed by

How we make and test puzzles: generation, solvability, difficulty labels, player review, and corrections.