4x4 Magic Square: Sum 34, 880 Squares and How to Solve One
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.
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.
| Row 1 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Row 2 | 5 | 6 | 7 | 8 |
| Row 3 | 9 | 10 | 11 | 12 |
| Row 4 | 13 | 14 | 15 | 16 |
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.
| Column 1 | Column 2 | Column 3 | Column 4 | Diagonal ↗ sum ↗ 34 | |
|---|---|---|---|---|---|
| Row 1 | 16 | 2 | 3 | 13 | Row 1 sum 34 |
| Row 2 | 5 | 11 | 10 | 8 | Row 2 sum 34 |
| Row 3 | 9 | 7 | 6 | 12 | Row 3 sum 34 |
| Row 4 | 4 | 14 | 15 | 1 | Row 4 sum 34 |
| Column sums | Column 1 sum 34 | Column 2 sum 34 | Column 3 sum 34 | Column 4 sum 34 | Diagonal ↘ 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.
- Find any row, column or diagonal with exactly one blank.
- Add the other three numbers and subtract the total from 34. That is the missing number.
- Write it in, then look again. Filling a cell often leaves another line with a single blank. Repeat until the grid is full.
- 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:
| Row 1 | 16 | blank | 3 | blank |
|---|---|---|---|---|
| Row 2 | blank | 11 | 10 | 8 |
| Row 3 | 9 | blank | blank | 12 |
| Row 4 | blank | 14 | blank | 1 |
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:
- Row 2: 11 + 10 + 8 = 29, so the blank is 34 − 29 = 5.
- Column 1 now has one blank: 16 + 5 + 9 = 30, so the blank is 4.
- Row 4: 4 + 14 + 1 = 19, so the blank is 15.
- Column 3: 3 + 10 + 15 = 28, so the blank is 6.
- Row 3: 9 + 6 + 12 = 27, so the blank is 7.
- Column 2: 11 + 7 + 14 = 32, so the blank is 2.
- Row 1: 16 + 2 + 3 = 21, so the blank is 13.
| Column 1 | Column 2 | Column 3 | Column 4 | Diagonal ↗ sum ↗ 34 | |
|---|---|---|---|---|---|
| Row 1 | 16 | 2 | 3 | 13 | Row 1 sum 34 |
| Row 2 | 5 | 11 | 10 | 8 | Row 2 sum 34 |
| Row 3 | 9 | 7 | 6 | 12 | Row 3 sum 34 |
| Row 4 | 4 | 14 | 15 | 1 | Row 4 sum 34 |
| Column sums | Column 1 sum 34 | Column 2 sum 34 | Column 3 sum 34 | Column 4 sum 34 | Diagonal ↘ 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).
| Row 1 | blank | blank | 3 | 13 |
|---|---|---|---|---|
| Row 2 | blank | blank | 10 | 8 |
| Row 3 | 9 | 7 | 6 | 12 |
| Row 4 | 4 | 14 | 15 | 1 |
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.
Square
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.
- 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).
- “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).
- 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.