Magic Square Calculator

Magic Square Calculator

Generate a magic square where every row, column, and diagonal adds to the same magic constant.

Last updated: June 2026 | By Patchworkr Team

Magic Square Generator
Magic Constant
15
Every row, column, and diagonal sums to 15.
Odd Order Construction
8
1
6
3
5
7
4
9
2

What Is a Magic Square?

A magic square is a square grid of numbers where each row, each column, and both diagonals have the same sum. That shared sum is called the magic constant.

How to Generate a Magic Square

  1. Choose an order that the generator supports.
  2. Use the odd-order or doubly-even construction rule.
  3. Compute the magic constant with M = n(n^2 + 1) / 2.
  4. Verify that every row, column, and diagonal matches the constant.
M = n(n^2 + 1) / 2

Worked Example

A 3x3 magic square has magic constant 15.

n = 3 -> M = 15

Frequently Asked Questions

Why are singly even orders unsupported?

The generator currently covers odd and doubly even orders only, because singly even squares need a separate construction.

Does the order have to be a whole number?

Yes. The order must be an integer of at least 3.

Can I use negative numbers?

Not with this generator. It builds standard consecutive-number magic squares.

What if I need a larger square?

You can enter a larger supported order, but the visual grid may require scrolling on smaller screens.

Related Tools