3x3 magic square: the solution and why it works

Last updated · By Perfect Magic Squares

A 3x3 magic square uses the numbers 1 to 9 once each, arranged so that every row, column and both diagonals add up to the same total. For 1 to 9 that total is 15, and the square looks like this.

The 3x3 magic square. Top row 2, 7, 6; middle row 9, 5, 1; bottom row 4, 3, 8. Every row, column and diagonal adds to 15.
276
951
438

Check it: the top row is 2 + 7 + 6 = 15, the middle column is 7 + 5 + 3 = 15, and the diagonal from top left is 2 + 5 + 8 = 15. The rest of this page explains why the sum has to be 15, why 5 has to sit in the middle, and why this is the only 3x3 square that uses 1 to 9 once each (apart from turning it and flipping it over). If you only want to solve a puzzle with some cells filled in, use the magic square solver.

Nine groups of dots in a three by three layout: four, nine and two dots in the top row; three, five and seven in the middle row; eight, one and six in the bottom row.
The traditional dot diagram of the Lo Shu square, the same magic square as the one above turned a quarter turn clockwise. Public domain, via Wikimedia Commons.

Why the sum is 15

Start with the numbers themselves: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45. Every one of those numbers sits in exactly one row, so the three rows together contain all nine numbers and add to 45. If the three rows have the same total, each one is 45 ÷ 3 = 15. The Math Doctors reach 15 the same way.

The columns work the same way, so every column also has to add to 15. The diagonals are not forced by this argument, which is why they are the part that makes the puzzle hard.

Why 5 goes in the centre

The centre cell is special because it lies on four lines: the middle row, the middle column and both diagonals. Every other cell lies on fewer. Add those four lines together and use c for the centre number:

  1. Four lines of 15 each: 4 × 15 = 60.
  2. Those four lines cover all nine cells once, and the centre three extra times, so they also add to 45 + 3c.
  3. So 45 + 3c = 60, which gives 3c = 15 and c = 5.

This matches the Math Doctors' observation that 5 is the only number that can appear in four of the eight lines (the three rows, three columns and two diagonals).

A useful consequence: each line through the centre has 5 in the middle, so the two cells at its ends add to 15 − 5 = 10. The numbers pair up across the centre as 1 and 9, 2 and 8, 3 and 7, 4 and 6. Look at the square above and you will see each pair facing each other.

Why the corners are even and the edges are odd

The four corner cells hold 2, 4, 6 and 8, and the four edge cells (the middle of each side) hold 1, 3, 7 and 9. This section proves it. If you only want the result, skip to the uniqueness section.

Opposite cells add to 10, so each opposite pair is both odd or both even. The odd pairs are 1 and 9, and 3 and 7. The even pairs are 2 and 8, and 4 and 6. Each diagonal joins one pair of opposite corners, so the corners are two such pairs. Every edge sits in a line of 15 (an odd total) with two corners, and there are three cases:

So the corners are 2, 4, 6 and 8, and the edges are 1, 3, 7 and 9.

Why there is only one 3x3 magic square

You can now finish the job by hand. The 2 sits in a corner, and turning the square lets you put it at the top left, which pushes 8 to the bottom right. The corners 4 and 6 fill the other two corners. Flipping the square along the diagonal that passes through 2 and 8 swaps those two corners without moving anything else, so you may choose 6 for the top right. The rest is forced:

That is the square at the top of the page. Every 3x3 magic square that uses 1 to 9 once each can be turned and flipped into it. MathWorld calls it the unique normal square of order three. So there is just one square of order three once rotations and reflections count as the same square. For order four the equivalent count is 880, as the 4x4 magic square guide explains.

To write the square from memory:

  1. Put 5 in the centre.
  2. Put 2 in a corner and 8 in the opposite corner.
  3. Put 4 and 6 in the other two corners.
  4. Fill each edge with 15 minus the two corners beside it.

The how to make a magic square guide covers larger sizes.

Other number sets do give other squares. Adding k to every cell of the 1-to-9 square gives a magic square with sum 15 + 3k, and its centre is always the sum ÷ 3. For example, the numbers 2 to 10 (k = 1) have sum 18 and centre 6.

The eight forms of the one square

Turning the square by quarter turns gives four versions, and flipping it over gives four more. That makes eight grids, all the same square seen from a different side. Use the buttons to move between them.

Form 1 of 8: the original. Rows read 2 7 6, 9 5 1, 4 3 8.
276
951
438

Form 1 of 8: the original. Every row, column and diagonal adds to 15.

A worked example: fill in the blanks

Here is a puzzle with four numbers missing. It uses the numbers 1 to 9, so the sum is 15 and the centre is 5. You do not need to guess: the centre is known, and every other blank is the last unknown in some line.

Puzzle: a 3x3 magic square with four blanks. Top row 2, blank, 6; middle row blank, blank, 1; bottom row 4, blank, 8.
2?6
??1
4?8
  1. The puzzle uses 1 to 9, so the sum is 15 and the centre is 5.
  2. Top row: 15 − 2 − 6 = 7, so the top middle is 7.
  3. Middle row: 15 − 5 − 1 = 9, so the middle left is 9.
  4. Bottom middle: it faces 7 across the centre, so it is 10 − 7 = 3.
  5. Check the columns: 2 + 9 + 4 = 15, 7 + 5 + 3 = 15 and 6 + 1 + 8 = 15.

If a puzzle uses other numbers, find the sum first (the total of all the numbers ÷ 3). The centre is sum ÷ 3, and opposite cells add to 2 × centre. For a puzzle with fewer clues on 1 to 9, start with the centre and use the pairs that add to 10. For more puzzles with answers, see the online magic square puzzle and the printable worksheets.

The Lo Shu connection

The 3x3 magic square is known in China as the Lo Shu, and MathWorld notes that the ancient Chinese already knew it. The dot diagram above is that square, and the history of magic squares tells the story and what came after it.

The formula behind 15

The same reasoning works for any size: the magic constant of an n × n square of the numbers 1 to n² is n(n² + 1) ÷ 2. For n = 3 that is 3 × (9 + 1) ÷ 2 = 15. The magic constant formula guide proves it and tabulates other sizes. The magic square generator will produce one for you.

Report an error