Magic Square Calculator

Quick answer

The magic square calculator builds an n × n magic square (n = 3 to 12) using the numbers 1 to n², in which every row, column and both diagonals add up to the same magic constant.

Magic square
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
Magic constant
34
Sum of all numbers
136

Magic squares have fascinated people for millennia, from the Chinese Lo Shu square to Dürer’s engraving Melencolia I. They are a playground for number patterns and a classic puzzle.

How to use the Magic Square Calculator

  1. Size of the square n

Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.

How it works

Odd sizes use the Siamese (de la Loubère) method, sizes divisible by 4 use the complement pattern on the diagonals, and other even sizes use Strachey’s method of combining four odd squares.

Formula

Magic constant M = n(n² + 1) / 2

Worked example

Inputs: Size of the square n: 4.
Results: Magic square = 16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
; Magic constant = 34; Sum of all numbers = 136.

Key terms

Magic constant
The common sum of each row, column and diagonal.

Frequently asked questions

What is the magic constant of a 3 × 3 square?

15.

Is there a 2 × 2 magic square?

No, it is impossible with distinct numbers 1 to 4.

How many 3 × 3 magic squares are there?

Essentially one; the others are its rotations and reflections.

What is Dürer's magic square?

A 4 × 4 square from 1514 whose bottom row contains the year, 15 14.

Sources

  1. Wolfram MathWorld: Magic square
  2. OpenStax: Contemporary Mathematics

Cite this calculator

Speedy Calculator. (2026). Magic Square Calculator. Speedy Calculator. https://speedycalculator.com/calculators/math/magic-square/

Embed this calculator on your website

Free for blogs, schools and businesses. Paste this code where the calculator should appear; it stays up to date automatically.