Magic Square — Definition, Formula & Examples
A magic square is a square grid filled with distinct numbers so that every row, every column, and both main diagonals all add up to the same total, called the magic constant.
An magic square is an arrangement of the integers in an array such that the sum of the entries in each row, each column, and each of the two main diagonals equals the magic constant .
Key Formula
Where:
- = The magic constant — the sum each row, column, and diagonal must equal
- = The number of rows (and columns) in the square
How It Works
To build a magic square, you place each number from to exactly once in the grid so that every line of numbers shares the same sum. For a square you use the numbers 1 through 9, and every row, column, and diagonal must total 15. One classic method for odd-sized squares is the Siamese method: start by placing 1 in the middle of the top row, then move diagonally up and to the right for each next number, wrapping around edges and dropping down one cell whenever the target cell is already occupied. Checking your work is simple — just add each row, column, and diagonal and confirm they all equal the magic constant.
Worked Example
Problem: Build a 3×3 magic square using the numbers 1 through 9.
Find the magic constant: Use the formula with n = 3.
Place the numbers: Arrange 1–9 in the grid so every row, column, and diagonal sums to 15. One classic arrangement is:
Verify: Check all rows, columns, and diagonals. For example: Row 1: 2 + 7 + 6 = 15. Column 2: 7 + 5 + 3 = 15. Main diagonal: 2 + 5 + 8 = 15. Every line totals 15.
Answer: The 3×3 magic square above uses the numbers 1–9 with a magic constant of 15.
Another Example
Problem: What is the magic constant for a 4×4 magic square?
Apply the formula: Substitute n = 4 into the magic constant formula.
Interpret: In a 4×4 magic square using the numbers 1 through 16, every row, column, and main diagonal must add up to 34.
Answer: The magic constant for a 4×4 magic square is 34.
Why It Matters
Magic squares appear in competition math and puzzle-solving courses, sharpening skills in logical reasoning and arithmetic fluency. They also introduce ideas used in combinatorics, such as Latin squares, which matter in experimental design and error-correcting codes. Historically, magic squares have fascinated mathematicians for over 2,000 years, from ancient China's Lo Shu square to Albrecht Dürer's famous 4×4 engraving.
Common Mistakes
Mistake: Forgetting to check the diagonals
Correction: A grid where only the rows and columns sum correctly is not a magic square. Both main diagonals must also equal the magic constant.
Mistake: Repeating a number or skipping one
Correction: Every integer from 1 to n² must appear exactly once. Double-check that no number is used twice and none is left out.
