How to make a magic square: odd and even methods

Last updated · By Perfect Magic Squares

You build a magic square by hand with one of three methods, and the method depends on the size. Odd sizes use the Siamese method, sizes divisible by 4 use a complement trick, and the remaining even sizes use Conway's LUX method. Only a 2 by 2 square is impossible.

Which method to use for a square of order n (cells per side).
Order nMethodIdea
OddSiamese (de la Loubère)Number along up-right diagonals.
Multiple of 4ComplementWrite the numbers in order, then flip the diagonals.
4m + 2LUX (Conway)Build an odd square, tag it, expand each cell into a 2 by 2 block.

Every method here fills a normal square, one that uses each of the numbers from 1 to n² once. That fixes the target sum, the magic constant: every line must add to n(n² + 1) / 2, which is 15 for n = 3, 34 for n = 4, 111 for n = 6 and 175 for n = 7. The magic constant formula guide derives it. The fastest way to see how any of these behave at other sizes is the magic square generator, which uses the same three methods.

Odd orders: the Siamese method

The Siamese method, also called de la Loubère's method, works for every odd order and for no even one. The method is named for the French diplomat Simon de la Loubère, who reported it from Siam (see the Siamese method article). The rules take one sentence: put 1 in the middle of the top row, then keep moving one cell up and to the right; if a move leaves the grid, wrap round to the opposite edge; if the cell you reach is already full, drop one cell down from the cell you just filled instead.

Here is a 3 by 3 square, so you can see each rule fire once.

  1. Put 1 in the middle of the top row.
  2. Up and right from the top row leaves the grid, so wrap to the bottom row: 2 goes in the bottom right.
  3. Up and right from there leaves the grid on the right, so wrap to the left side: 3 goes in the middle row, far left.
  4. Up and right from 3 is the cell holding 1, which is full. Drop down one cell from 3 instead: 4 goes in the bottom left.
  5. Up and right from 4 is the centre, so 5 goes there. Up and right again gives the top right, so 6 goes there.
  6. Up and right from 6 wraps all the way round to the bottom left, which holds 4. Drop down from 6 instead: 7 goes in the middle row, far right.
  7. Up and right from 7 wraps to the top left, so 8 goes there.
  8. Up and right from 8 wraps to the bottom row, middle column, so 9 goes there.
The 3 by 3 square the Siamese method gives. Top row 8, 1, 6; middle row 3, 5, 7; bottom row 4, 9, 2. Every row, column and diagonal adds to 15.
816
357
492

The same rules scale to any odd size. This is the 7 by 7 square they produce, where every row, column and diagonal adds to 175.

The 7 by 7 Siamese square. Rows from the top: 30, 39, 48, 1, 10, 19, 28; 38, 47, 7, 9, 18, 27, 29; 46, 6, 8, 17, 26, 35, 37; 5, 14, 16, 25, 34, 36, 45; 13, 15, 24, 33, 42, 44, 4; 21, 23, 32, 41, 43, 3, 12; 22, 31, 40, 49, 2, 11, 20. Every row, column and diagonal adds to 175.
3039481101928
384779182729
466817263537
5141625343645
1315243342444
2123324143312
2231404921120

For a complete walk-through of the rules at one size, including what to do when the diagonal move is blocked, follow the 5x5 magic square guide, which builds that square in eight stages. The 3 by 3 case is also taken apart, with a proof that it is the only one, in the 3x3 magic square guide.

Multiples of 4: the complement method

When n is divisible by 4 you do not need to place numbers one by one. Write 1 to n² in order, row by row, then replace each number v on the diagonals of every 4 by 4 block with its complement, n² + 1 − v. Each diagonal cell takes the value of the cell opposite it through the centre, which is the idea behind the standard doubly even construction. In the 4 by 4 example, row 1 rises from 10 to 34 and row 4 falls from 58 to 34, so the unequal rows are all brought to 34.

Before: the numbers 1 to 16 written in order, row by row. The rows add to 10, 26, 42 and 58, so it is not magic yet.
1234
5678
9101112
13141516
After: each number on the two diagonals replaced by 17 minus itself. Rows from the top: 16, 2, 3, 13; 5, 11, 10, 8; 9, 7, 6, 12; 4, 14, 15, 1. Every row, column and diagonal now adds to 34.
162313
511108
97612
414151

On an 8 by 8 square, in every 4 by 4 block, replace the cells on that block's two diagonals, using the numbers 1 to 64 written in order across the whole grid. The complement there is 65 − v everywhere, not the 4 by 4 rule:the first row 1 to 8 becomes 64, 2, 3, 61, 60, 6, 7, 57, which adds to 260. The last row 57 to 64 becomes 8, 58, 59, 5, 4, 62, 63, 1, which also adds to 260. The 4x4 magic square guide covers that size in depth, including how to finish a partly filled grid.

Orders 4m + 2: the LUX method

The remaining even orders (6, 10, 14 and so on) are the awkward ones: the Siamese method does not apply and the complement trick fails. MathWorld credits an elegant method for these singly even orders to J. H. Conway, who calls it the LUX method. For a square of order 4m + 2, the Wikipedia article on the LUX method starts with a (2m + 1) by (2m + 1) array: m + 1 rows of the letter L, one row of U and m − 1 rows of X, with the middle U exchanged with the L above it. Each letter then stands for a 2 by 2 block of four consecutive numbers. The base array is the Siamese square that starts with 1 in the top-middle cell. For 10 by 10, m is 2, so the 5 by 5 base gets 3 rows of L, 1 row of U and 1 row of X.

The three block layouts. The numbers 4k − 3, 4k − 2, 4k − 1 and 4k go into the positions marked 1, 2, 3 and 4.
LUX
4 1
2 3
1 4
2 3
1 4
3 2

Here it is on the smallest case that works, 6 by 6, where m is 1. The figures below show three stages, and the buttons that appear above them (when scripts are on) move between them one at a time.

Stage 1. The 3 by 3 Siamese square with an L, U or X tag in each cell: two rows of L on top, then one row of U, and no rows of X because m − 1 is 0. Top row 8 L, 1 L, 6 L; middle row 3 L, 5 L, 7 L; bottom row 4 U, 9 U, 2 U.
8 L1 L6 L
3 L5 L7 L
4 U9 U2 U
Stage 1: build the odd square with the Siamese method, then tag m + 1 = 2 rows L and the last row U.
Stage 2. The same numbers with the tags after the swap: the middle cell of the middle row is now U and the middle cell of the bottom row is now L. Tags: top row L, L, L; middle row L, U, L; bottom row U, L, U.
8 L1 L6 L
3 L5 U7 L
4 U9 L2 U
Stage 2: swap the middle U with the L above it. Only those two tags change.
Stage 3. The finished 6 by 6 square. Rows from the top: 32, 29, 4, 1, 24, 21; 30, 31, 2, 3, 22, 23; 12, 9, 17, 20, 28, 25; 10, 11, 18, 19, 26, 27; 13, 16, 36, 33, 5, 8; 14, 15, 34, 35, 6, 7. Every row, column and diagonal adds to 111.
3229412421
3031232223
12917202825
101118192627
1316363358
1415343567
Stage 3: replace each cell k with a 2 by 2 block of the numbers 4k − 3 to 4k, laid out by its letter as in the table above. X does not appear at this size.

To expand a cell by hand, take its number k and write the four numbers 4k − 3, 4k − 2, 4k − 1 and 4k in the positions its letter gives in the table above. The 8 in the top left, tagged L, becomes 32 and 29 over 30 and 31 (4 × 8 = 32 is the largest of the four). Doing that for all nine cells gives stage 3. Larger orders use the same recipe with a bigger odd base square.

Why there is no 2 by 2 square

A normal 2 by 2 square would use 1 to 4, which total 10, so each row and column would have to add to 5. The only pairs adding to 5 are 1 and 4, and 2 and 3, so the cell holding 1 would need a 4 beside it in its row and also a 4 below it in its column, and one 4 cannot fill both. Wikipedia states that normal magic squares exist for all sizes except 2 by 2.

Check your square: add every line

Whatever method you used, finish by adding every line. An n by n square has n rows, n columns and 2 diagonals, so a 6 by 6 has 14 lines to add. Compare each total with n(n² + 1) / 2, and no number from 1 to n² may be missing or repeated. A slip in the Siamese method is usually a blocked cell handled with an up-right move instead of a drop down; a slip in LUX is usually a letter pattern written the wrong way round. If the totals disagree, the magic square solver will show which lines are off.

Report an error