The Mathematics and Construction of Magic Squares

This article explores the concept of magic squares in recreational mathematics. It defines what a magic square is, explains the mathematical formula behind its constant sum, and provides clear, step-by-step methods that researchers and puzzle enthusiasts use to construct odd, doubly even, and singly even grids.

What is a Magic Square?

A magic square is a square grid of size \(n \times n\) filled with distinct positive integers—typically from \(1\) to \(n^2\)—such that the sum of the numbers in any horizontal row, vertical column, and both main diagonals equals the exact same number.

In mathematics, the number of cells on one side of the grid (\(n\)) is called the "order" of the magic square. The constant sum shared by every row, column, and diagonal is known as the "magic constant" or "magic sum." Note that a \(1 \times 1\) grid is trivial, and it is mathematically impossible to construct a \(2 \times 2\) magic square using distinct numbers. Therefore, standard magic squares start at order 3.

Calculating the Magic Constant

Before constructing a magic square, researchers determine its magic constant (\(M\)) using a straightforward mathematical formula based on the grid's order (\(n\)):

\(M = \frac{n(n^2 + 1)}{2}\)

For example, in a \(3 \times 3\) magic square (\(n = 3\)), the numbers \(1\) through \(9\) are used. Applying the formula gives:

\(M = \frac{3(3^2 + 1)}{2} = \frac{3(10)}{2} = 15\)

Every row, column, and diagonal in a standard \(3 \times 3\) magic square must sum to 15. For a \(4 \times 4\) square, the constant is 34; for a \(5 \times 5\) square, it is 65.

How to Construct Magic Squares

Recreational researchers categorize construction algorithms into three distinct types, depending on whether the order (\(n\)) of the square is odd, doubly even, or singly even.

1. Odd-Order Magic Squares (3x3, 5x5, 7x7, etc.)

When \(n\) is an odd number, the simplest construction algorithm is the Siamese method (also known as De la Loubère's method).

  1. Place the number 1 in the center box of the very top row.
  2. Move diagonally up one row and right one column to place the next sequential number.
  3. Wrapping Rule: If a diagonal move takes you outside the grid, wrap around to the opposite side. If you go above the top row, drop to the bottom row of that target column. If you go past the rightmost column, wrap to the leftmost column of that target row.
  4. Blocked Rule: If the target cell is already filled with a number, or if you just placed a number in the exact top-right corner of the grid, do not move diagonally. Instead, move directly down one space from your current position to place the next number, then resume the diagonal pattern.

2. Doubly Even Magic Squares (4x4, 8x8, 12x12, etc.)

A doubly even square has an order that is a multiple of 4. Researchers construct these using a diagonal inversion method.

  1. Draw the grid and divide it into \(4 \times 4\) sub-squares (a \(4 \times 4\) grid is just one sub-square, while an \(8 \times 8\) grid has four).
  2. Lightly mark all the cells that fall on the two main diagonals of every \(4 \times 4\) sub-square.
  3. Starting at the top-left corner of the main grid, count sequentially from \(1\) to \(n^2\), moving left to right across each row, going top to bottom.
  4. Write the number down only if the cell is unmarked. Skip the marked diagonal cells, but keep counting upward as you pass them.
  5. Once you reach the end, start over at the bottom-right corner. Count sequentially from \(1\) to \(n^2\) again, this time moving right to left, bottom to top.
  6. Fill in the remaining empty (marked) diagonal cells with the numbers corresponding to your new count.

3. Singly Even Magic Squares (6x6, 10x10, 14x14, etc.)

Singly even squares have an order that is divisible by 2, but not by 4. These are the most difficult to build and require the Strachey method, which breaks the grid into smaller odd-order squares.

  1. Divide the grid into four equal quadrants, each being an odd-order square of size \(\frac{n}{2} \times \frac{n}{2}\). Label the top-left quadrant A, the bottom-right B, the top-right C, and the bottom-left D.
  2. Use the Siamese method (for odd squares) to fill each quadrant sequentially.
    • Fill Quadrant A with numbers \(1\) to \(\frac{n^2}{4}\).
    • Fill Quadrant B with numbers \(\frac{n^2}{4} + 1\) to \(\frac{n^2}{2}\).
    • Fill Quadrant C with numbers \(\frac{n^2}{2} + 1\) to \(\frac{3n^2}{4}\).
    • Fill Quadrant D with the remaining numbers up to \(n^2\).
  3. At this stage, the columns will sum to the magic constant, but the rows and diagonals will not. To fix this, specific cells must be swapped between the top and bottom quadrants.
  4. For a \(6 \times 6\) grid, look at the leftmost column of Quadrant A and Quadrant D. Swap the top-left cell of A with the top-left cell of D, and the bottom-left cell of A with the bottom-left cell of D. For the middle row of these quadrants, shift one space to the right and swap the center cell of A with the center cell of D. (Larger singly even grids require swapping additional columns between A and D, as well as C and B, scaling with the size of the grid).