Magic Square Solver
Arrange numbers so every row, column, and both diagonals sum to the same magic constant. Choose a size, generate a puzzle, and try to solve it.
About Magic Squares
A magic square of order n is an n×n grid filled with the integers 1 to n², arranged so that every row, every column, and both main diagonals sum to the same number — the magic constant: M = n(n²+1)/2. For a 3×3, M=15; for a 4×4, M=34; for a 5×5, M=65. Magic squares have fascinated mathematicians for thousands of years and appear in cultures worldwide.
Different construction methods exist depending on n: the Siamese (de la Loubère) method works for odd orders, the diagonal-swap method for 4×4 (doubly-even), and more complex schemes for singly-even orders like 6×6. This solver generates authentic magic squares for sizes 3–7 and lets you try to fill in partially removed cells.
Frequently Asked Questions
What is the magic constant?
The magic constant M is the sum that every row, column, and diagonal must equal. For order n it is M = n(n²+1)/2. So: 3×3→15, 4×4→34, 5×5→65, 6×6→111, 7×7→175.
How many magic squares exist?
For 3×3 there is essentially one (up to rotation/reflection). For 4×4 there are 880 distinct squares. For 5×5 there are over 275 million, and the count grows very rapidly.
What construction method do you use?
Odd orders (3, 5, 7) use the Siamese (de la Loubère) method. Order 4 uses the diagonal-swap method. Order 6 uses a precomputed valid square.
Does every magic square have diagonals summing to M?
By the classical definition, yes — all rows, columns, and both main diagonals must sum to M. These are called "normal" magic squares.