Math
Magic Square Calculator
Choose an order to generate a magic square whose rows, columns, and both diagonals all add to the same magic constant.
Odd orders use the Siamese method (start at the top middle, move up and to the right), and orders divisible by 4 use the diagonal-swap method. The grid is drawn with the diagonals shaded and every line sum listed. Switch to verify mode to paste a square of your own and check it line by line.
3, 5, 7, 9, 11 (odd) or 4, 8, 12 (doubly even). Orders 6 and 10 are not built here.
Try an example
Result
Magic constant / verdict
—
- Row sums
- —
- Column sums
- —
- Diagonal sums
- —
- Method
- —
Student quick launch
Grade planning, algebra checks, and formulas students reach for most.
Study path
Use this calculator with
Follow these when you want the formula behind the answer, a short lesson, or nearby tools in the same topic.
What the magic square calculator solves
A magic square is an n × n grid of numbers in which every row, every column, and both main diagonals add to the same total, the magic constant. A normal magic square uses each of 1, 2, …, n² exactly once. The 3 × 3 square (the Lo Shu) has constant 15, the 4 × 4 in Dürer's Melencolia I has constant 34, and in general the constant is n(n² + 1)/2. This calculator builds such squares and checks any square you enter.
| Order n | Magic constant | Construction | Number of distinct normal squares (up to symmetry) |
|---|---|---|---|
| 3 | 15 | Siamese | 1 |
| 4 | 34 | doubly even | 880 |
| 5 | 65 | Siamese | 275,305,224 |
| 6 | 111 | LUX / Strachey (not built here) | ≈ 1.8 × 10^19 |
| 7 | 175 | Siamese | unknown exactly |
| 8 | 260 | doubly even | unknown exactly |
The Siamese method for odd orders
Place 1 in the middle cell of the top row. For each next number move one cell up and one to the right, wrapping around the edges (off the top means the bottom row, off the right means the first column). If that cell is already filled, place the number directly below the previous one instead. After n² numbers the square is magic. The center cell of an odd square is always (n² + 1)/2.
Doubly-even orders (4, 8, 12)
Write 1 through n² in reading order. Divide the square into 4 × 4 blocks and, in every block, replace each entry on the two diagonals by n² + 1 minus itself. The swapped and unswapped cells balance so that every line sums to the constant. Singly-even orders (6, 10) need the more involved LUX method and are not generated here, though they can be verified.
How to use it
- Pick Generate and an order from 3 to 12 (not 6 or 10) to build a square; the grid is drawn with the diagonals shaded.
- Pick Verify and paste a square, one row per line, to see every row, column, and diagonal sum and which lines fail.
- Open Show the work for the magic-constant formula, the construction rule, and the verification sums.
How to read the answer
For a generated square the primary result is the magic constant, and every row, column, and diagonal sum listed underneath equals it. For a verified square the verdict says whether all 2n + 2 line sums match; a magic square that does not use 1 … n² is flagged as magic but not normal, and any mismatched lines are named so you can find the error.
Common mistakes and edge cases
- Checking only rows and columns; both diagonals must match too (a square that fails the diagonals is 'semi-magic').
- Applying the Siamese method to an even order; it only works for odd n.
- Expecting a 2 × 2 magic square; none exists with distinct entries.
- Confusing the magic constant with the largest entry: the 5 × 5 square uses numbers up to 25 but sums to 65.
- Typing rows of different lengths in verify mode; the square must be n × n.
Worked examples
5 × 5 by the Siamese method
Magic constant 65.
Magic constant / verdict
65
3 × 3 (Lo Shu)
Magic constant 15.
Magic constant / verdict
15
4 × 4 doubly even
Magic constant 34.
Magic constant / verdict
34
12 × 12
Largest size here, constant 870.
Magic constant / verdict
870
Verify the Lo Shu square
2 7 6 / 9 5 1 / 4 3 8.
Magic constant / verdict
Yes, magic constant 15
Verify Dürer's square
16 3 2 13 / 5 10 11 8 / 9 6 7 12 / 4 15 14 1.
Magic constant / verdict
Yes, magic constant 34
Not magic
Reading-order 1 … 9 fails.
Magic constant / verdict
No, not a magic square
Order 6
Singly even orders are not generated.
Magic constant / verdict
Error
Frequently asked questions
What is a magic square?+
An n × n grid where every row, column, and both main diagonals add to the same number, the magic constant. A normal magic square uses 1 through n² once each.
What is the magic constant formula?+
M = n(n² + 1)/2. For 3 × 3 it is 15, for 4 × 4 it is 34, for 5 × 5 it is 65.
How do I make a 3 × 3 magic square?+
Put 5 in the center, the even numbers in the corners, and pair opposite cells to sum to 10. One arrangement: 2 7 6 / 9 5 1 / 4 3 8. All others are rotations or reflections.
What is the Siamese method?+
A rule for odd orders: start with 1 in the top middle, move up-right for each next number (wrapping around), and drop down one cell when the target is occupied.
Is there a 2 × 2 magic square?+
No. Four distinct numbers cannot make both rows, both columns, and both diagonals equal.
Why can't this page build a 6 × 6?+
Orders that are even but not divisible by 4 need the LUX or Strachey construction, which is more involved than the two methods implemented here. You can still verify a 6 × 6 square.
How many 4 × 4 magic squares are there?+
880 essentially different normal 4 × 4 magic squares (7,040 counting rotations and reflections).
About this calculator
- Written by
- mathcheck editorial team
- Last reviewed
- September 4, 2026
Method
- Uses the values entered by the user and stable formulas documented on the page.
Related calculators
Triangular Numbers Calculator
Compute the nth triangular number T_n = n(n + 1)/2, test whether a number is triangular with the 8N + 1 perfect-square test and recover its index, list the triangular numbers up to a limit, and sum the first n triangular numbers.
Arithmetic Series Calculator
Find the sum of an arithmetic series from the first term, common difference, and number of terms, or from the first and last terms, with a partial-sum table and Gauss's pairing explained.
Perfect Square Calculator
Test whether a number is a perfect square with the exact root, the prime-factor reason, the nearest perfect squares below and above, and a list of all perfect squares in any range, computed exactly for numbers up to 60 digits.
Sum of Series Calculator
Sum arithmetic and geometric series with the closed-form formulas, partial sums, and the infinite geometric series when |r| < 1, with a convergence check and step-by-step work.
Pascal's Triangle Calculator
Generate Pascal's triangle up to 40 rows exactly, look up any binomial coefficient C(n, k) with the row highlighted, and see row sums, Pascal's rule, and the factorial formula.
Completing the Square Calculator
Complete the square on ax^2 + bx + c step by step: every algebraic line shown, exact fractions, vertex form a(x - h)^2 + k, the vertex, and the roots as simplified radicals.
Last updated: September 4, 2026