Magic Square Generator

Generate a magic square where every row, column and diagonal sums to the same magic constant, for odd orders and multiples of 4.

100% FreeNo sign-upPrivate — runs in your browser
—

Result

Magic constant
—
Order
—
Row/column/diagonal check
—

        

Copied to clipboard

How to use this tool

1
Choose the order

Enter an odd order (3, 5, 7, 9) or a multiple of 4 (4, 8).

2
Read the square

Read the generated grid in the results area.

3
Check the constant

Confirm every row, column and diagonal sums to the magic constant.

4
Reuse it

Copy the grid for puzzles, worksheets or recreational maths.

Formula & worked example

Magic constant = n(n² + 1) / 2 for a normal magic square using 1 to n².

The classic 3 × 3 square (8 1 6 / 3 5 7 / 4 9 2) has every row, column and diagonal summing to 15.

Limitations — read this before you rely on it

Covers odd orders and doubly-even orders from 3 to 9. Singly-even orders (6, 10, …) are not generated; the tool says so rather than giving a wrong square.

Frequently asked questions

A grid of distinct numbers where every row, column and both main diagonals add to the same magic constant.

For order n using 1 to n², it is n(n² + 1) / 2: 15 for 3 × 3, 34 for 4 × 4, 65 for 5 × 5.

The classic construction for odd orders: place 1 in the top-middle, then move up-right, dropping down when the next cell is taken.

Singly-even orders need a more involved construction (the Strachey method); this tool covers odd orders and multiples of 4.

No. Rotations and reflections of one square give others with the same constant.