Magic Square Calculator — Magic Constant and Grid
Find the magic constant for any n×n magic square and see the actual grid — every row, column and diagonal in the result sums to the same number.
Every row, column and diagonal sums to 15
Formula for the magic constant
Sum of all integers 1 to n²
Each row/col/diagonal must sum to M
8
1
6
3
5
7
4
9
2
- 1
Compute n²
n² = 3 × 3 = 9 - 2
n² + 1
9 + 1 = 10 - 3
Magic constant M = n × (n² + 1) ÷ 2
3 × 10 ÷ 2 = 15Every row, column and diagonal of the magic square sums to M.
How does this calculator work?
The magic constant for an n×n magic square is M = n(n²+1)/2 — every row, column and diagonal sums to M. For n=3: M=15; n=4: M=34; n=5: M=65. Odd-order squares are constructed with the Siamese method; 4×8 doubly-even squares with the diagonal-complement swap.
Formula
How this is calculated
A magic square is an n×n grid filled with the distinct integers 1 to n², arranged so that every row, every column, and both main diagonals all sum to the same number — the magic constant M. The magic constant follows directly from the sum of all integers 1 to n², which equals n²(n²+1)/2, divided equally among the n rows: M = n(n²+1)/2. For n=3, M=15; for n=4, M=34; for n=5, M=65.
This calculator constructs the actual grid for odd-order squares (n = 1, 3, 5, 7, 9) using the Siamese (de la Loubère) method: place 1 in the middle of the top row, then move one cell up and one to the right (wrapping around), placing consecutive integers. If the target cell is already occupied, drop down one row instead and continue. This elegant algorithm produces a valid magic square for every odd n.
For doubly-even orders (n divisible by 4: n = 4, 8), the diagonal-complement swap method is used: fill the grid 1 to n² in order, then replace every cell that lies on a diagonal of a 4×4 sub-block with its complement (n²+1 − x). Singly-even orders (n = 6, 10, …) require the more complex Strachey method, so this calculator shows only the magic constant for those sizes.
Frequently asked questions
M = 3(9+1)/2 = 15. Every row, column and both diagonals of the classic 3×3 magic square (Lo Shu) sum to 15. The only essentially distinct 3×3 magic square is: 2,7,6 / 9,5,1 / 4,3,8 (rotations and reflections aside).
No. A 2×2 magic square using distinct positive integers cannot exist. The magic constant would be M = 2(4+1)/2 = 5, requiring each row and column to sum to 5, but any arrangement of 1,2,3,4 fails at least one row, column or diagonal.
The Siamese (de la Loubère) method places 1 in the middle of the top row, then moves diagonally up-right, wrapping around edges, for each successive number. If a cell is already occupied, move down one row instead. It produces a valid magic square for every odd n and was brought to France from Siam in the 17th century.
TG we-Calculate Editorial Team. (2026). Magic Square Calculator — Magic Constant and Grid [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/magic-square-calculator
TG we-Calculate Editorial Team. "Magic Square Calculator — Magic Constant and Grid." TG we-Calculate. 2026. https://we-calculate.com/calculator/magic-square-calculator.
TG we-Calculate Editorial Team, "Magic Square Calculator — Magic Constant and Grid," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/magic-square-calculator
@misc{wecalculate_magic_square_calculator, title = {Magic Square Calculator — Magic Constant and Grid}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/magic-square-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
