Advertisement

Magic square calculator

Enter the square size n. A normal square uses every integer from 1 to n squared exactly once. Order 2 has no normal magic square.

Calculator

Magic constant
15
Square rows
Row 1: 8, 1, 6; Row 2: 3, 5, 7; Row 3: 4, 9, 2
Numbers used
1 to 9, each used once

Advertisement

How this calculator works

Every row, column and the two main diagonals of a normal magic square share a sum. Odd sizes use an upward-right placement pattern; multiples of four use complementary cells; other even sizes combine and exchange blocks from an odd square. The complete square appears as numbered text rows. The size cap keeps the output readable.

Formula

Magic constant M = n(n^2 + 1)/2, because 1 + 2 + ... + n^2 is divided equally among n rows.

Worked example

A 3 by 3 square is 8, 1, 6 / 3, 5, 7 / 4, 9, 2. Each row, column and main diagonal totals 15. A normal 4 by 4 square has magic constant 34.

Advertisement

Frequently asked questions

Why is order 2 impossible?

Equal row and column sums would force repeated entries, which violates the requirement to use 1 through 4 once each.

Does this list every magic square?

No. It constructs one normal square for the chosen size. Rotations, reflections and other arrangements may also work.

Are all diagonal directions checked by the definition?

Only the two main corner-to-corner diagonals must match. Other diagonal paths need not have the magic sum.

Sources

Advertisement