How to make a magic square: odd and even methods
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.
| Order n | Method | Idea |
|---|---|---|
| Odd | Siamese (de la Loubère) | Number along up-right diagonals. |
| Multiple of 4 | Complement | Write the numbers in order, then flip the diagonals. |
| 4m + 2 | LUX (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.
- Put 1 in the middle of the top row.
- Up and right from the top row leaves the grid, so wrap to the bottom row: 2 goes in the bottom right.
- 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.
- 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.
- Up and right from 4 is the centre, so 5 goes there. Up and right again gives the top right, so 6 goes there.
- 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.
- Up and right from 7 wraps to the top left, so 8 goes there.
- Up and right from 8 wraps to the bottom row, middle column, so 9 goes there.
| 8 | 1 | 6 |
| 3 | 5 | 7 |
| 4 | 9 | 2 |
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.
| 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 |
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.
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 |
| 16 | 2 | 3 | 13 |
| 5 | 11 | 10 | 8 |
| 9 | 7 | 6 | 12 |
| 4 | 14 | 15 | 1 |
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.
| L | U | X |
|---|---|---|
| 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.
| 8 L | 1 L | 6 L |
| 3 L | 5 L | 7 L |
| 4 U | 9 U | 2 U |
| 8 L | 1 L | 6 L |
| 3 L | 5 U | 7 L |
| 4 U | 9 L | 2 U |
| 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 |
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.