4x4 Magic Square: Sum 34, 880 Squares and How to Solve One

Last updated · By Perfect Magic Squares

A 4x4 magic square is a grid of the numbers 1 to 16, each used once, in which every row, column and both long diagonals add up to the same total. That total, the magic sum, is always 34, from M = 4(16 + 1)/2.

Black-and-white engraving of a brooding winged figure seated beside a polyhedron, a sleeping dog and a sphere, with a four-by-four grid of numbers hanging on the wall at upper right
The best-known 4x4 magic square hangs on the wall of Dürer’s engraving Melencolia I (upper right). Public domain, via Wikimedia Commons. It has its own guide; this page is about 4x4 squares in general.

Below you can build a 4x4 square by hand, finish a half-filled grid with one simple routine, see why there are exactly 880 different squares, and step through all of them. The routine has a limit, and the page says where it stops working.

Why the sum is 34

For any normal magic square of order n, the magic constant is M = n(n² + 1)/2 (MathWorld). Put n = 4 and you get 4(16 + 1)/2, and Wikipedia confirms that every normal magic square of order four has magic sum 34.

The idea behind the formula is short. The numbers 1 to 16 add up to 136, and the four rows must share that total equally, so each row is 136 ÷ 4 = 34. The columns and diagonals must match the rows. The magic constant guide gives the full derivation for any size.

Build a 4x4 magic square by hand

A 4x4 square has a quick construction. Write the numbers 1 to 16 in order across the rows, starting at the top left. Then replace each number v on the two long diagonals with 17 − v.

Step one: write 1 to 16 in order. The diagonal cells (1, 6, 11, 16 and 4, 7, 10, 13) are the ones to replace.
Row 11234
Row 25678
Row 39101112
Row 413141516

Replacing the marked numbers turns 1 into 16, 6 into 11, 11 into 6 and 16 into 1 on the main diagonal, and 4 into 13, 7 into 10, 10 into 7 and 13 into 4 on the other. Everything off the diagonals stays put.

Step two: the finished 4x4 magic square. Row sums are on the right, column sums underneath and the two diagonal sums in the corners; all ten are 34.
Column 1Column 2Column 3Column 4Diagonal ↗ sum ↗ 34
Row 1162313Row 1 sum 34
Row 2511108Row 2 sum 34
Row 397612Row 3 sum 34
Row 4414151Row 4 sum 34
Column sumsColumn 1 sum 34Column 2 sum 34Column 3 sum 34Column 4 sum 34Diagonal ↘ sum ↘ 34

Check it by adding. Rows: 16 + 2 + 3 + 13, 5 + 11 + 10 + 8, 9 + 7 + 6 + 12 and 4 + 14 + 15 + 1 are all 34. Columns: 16 + 5 + 9 + 4, 2 + 11 + 7 + 14, 3 + 10 + 6 + 15 and 13 + 8 + 12 + 1 are all 34. Diagonals: 16 + 11 + 6 + 1 and 13 + 10 + 7 + 4 are 34.

Wikipedia’s version of this construction keeps the diagonals and replaces every other number with 17 − v. That gives 1 15 14 4 / 12 6 7 9 / 8 10 11 5 / 13 3 2 16, the 17-complement of the square above, and the complement of a magic square is always magic (Wikipedia).

A property of this square, not of every square

In this particular square, any cell and the cell opposite it through the centre add to 17: 16 and 1, 2 and 15, 3 and 14, 13 and 4, 5 and 12, 11 and 6, 10 and 7, 8 and 9. That follows from how this square was built. It is a pattern in this construction, and it is a lovely way to check your work, but it is not a rule that magic squares must obey. Most of the 880 different 4x4 squares are not centre-symmetric in this way, so never use the 17-pair trick to fill in someone else’s grid. The viewer further down shows, square by square, whether the pairs add to 17.

Finish a partly filled 4x4 grid

If you have a grid with some numbers missing, line completion is the simplest method and needs nothing but the sum of 34. This assumes the grid uses 1 to 16. If the puzzle uses other numbers, take the target from any complete line, or from (sum of all the numbers) ÷ 4.

  1. Find any row, column or diagonal with exactly one blank.
  2. Add the other three numbers and subtract the total from 34. That is the missing number.
  3. Write it in, then look again. Filling a cell often leaves another line with a single blank. Repeat until the grid is full.
  4. If no line has a single blank, list the numbers still unused. A line with two blanks needs a pair from that list that adds up to the line’s shortfall. If two pairs fit, pick one, keep going, and if a line fails, go back and try the other.

Check your answer by adding every row, column and diagonal at the end.

A worked example in which filling one cell unlocks the next:

Start: nine cells are given and seven are blank.
Row 116blank3blank
Row 2blank11108
Row 39blankblank12
Row 4blank14blank1

Several lines start with a single blank: row 2, column 4 and the main diagonal. Any of them works; this walkthrough starts with row 2 and keeps both diagonals back as the final check. Each answer creates the next single-blank line:

Finished: every blank was forced, and all ten lines add to 34.
Column 1Column 2Column 3Column 4Diagonal ↗ sum ↗ 34
Row 1162313Row 1 sum 34
Row 2511108Row 2 sum 34
Row 397612Row 3 sum 34
Row 4414151Row 4 sum 34
Column sumsColumn 1 sum 34Column 2 sum 34Column 3 sum 34Column 4 sum 34Diagonal ↘ sum ↘ 34

I never used the diagonals to find a number, yet both come out at 34. That agreement is your check.

When line completion stalls

Sometimes every line with a blank has at least two of them. Then step one finds nothing, and the routine cannot continue. A stall happens when every blank shares its row and column with another blank, for example a 2x2 block of blanks (or any two rows crossed with two columns).

A stalled grid: the blanks form a two-by-two block, and no row, column or diagonal has exactly one blank.
Row 1blankblank313
Row 2blankblank108
Row 397612
Row 4414151

Step 4 rescues this grid. The numbers not yet shown are 2, 5, 11 and 16. Row 1 needs 18 from two of them, and only 2 + 16 works. Row 2 needs 16, and only 5 + 11 works. Column 1 then needs 21 from its two blanks (34 − 9 − 4), and only 16 + 5 works, so the top left is 16 and the cell below it is 5. Row 1 needs 2 in its remaining blank and row 2 needs 11, so the grid is 16 2 3 13 / 5 11 10 8 / 9 7 6 12 / 4 14 15 1, and every line adds to 34.

When several pairs fit, send the grid to the magic square solver, which tries every possibility and lists all completions with their line sums. Some grids have more than one: with rows 2 and 3 blank, 5 11 10 8 / 9 7 6 12 and 9 7 6 12 / 5 11 10 8 both work. To practise on easier grids first, try the magic square puzzle.

How many 4x4 magic squares are there?

There are 880 distinct 4x4 magic squares. MathWorld notes that Frénicle de Bessy enumerated the 880 squares of order four in 1693, and Wikipedia’s article on the magic square gives the same count.

That figure treats a square and its rotations and reflections as one. A square has eight such forms, and for 4x4 they are all different, so counting each form separately gives 880 × 8 = 7,040 grids. Both numbers appear in the viewer below, where they are counted by running a search rather than being taken on trust.

Browse all 880 squares

This viewer asks the same solver used on the solver page for every completion of an empty 4x4 grid, then merges grids that are rotations or reflections of each other. It takes about a second and runs in the background so the page stays responsive. If the browser finds a different number from the cited 880, the status line will say so.

Each square is shown in whichever of its eight forms sorts first, which is why the list does not start with the familiar 16 in the corner. Step through a few and the 17-pair pattern from the square above turns up only now and then; the status line counts exactly how many.

Method and sources

The squares and sums above were re-added by hand, and the counts in the viewer come from a search of all grids. The search lists 7,040 completions and, after merging rotations and reflections, 880 squares.

  1. Weisstein, Eric W. “Magic Square.” MathWorld, A Wolfram Resource. mathworld.wolfram.com/MagicSquare.html (the formula for the magic constant and the count of 880 squares of order four, with Frénicle de Bessy and 1693).
  2. “Magic square.” Wikipedia. en.wikipedia.org/wiki/Magic_square (magic sum for order four, the count of 880 distinct squares, and the complement of a square).
  3. Constructions of magic squares. Wikipedia. en.wikipedia.org/wiki/Constructions_of_magic_squares (the doubly even construction, which keeps the diagonals and replaces the other numbers; the result is the 17-complement of the square built here).

For other sizes see how to make a magic square, or return to the magic square generator.

Report an error