Productivity and Utilities

Magic Square Generator

Choose the size of the square to generate it and see the magic constant every line adds to.

Your numbers

A whole number from 3 to 16. Example value.

More options

The smallest number in the square. Use 1 for the classic square. Example value.

The gap between consecutive numbers. Example value.

Result

Magic constant

65

Every row, column and both diagonals add up to this in a 5 by 5 square.

Magic constant
65
Cells
25
Numbers used
1 to 25
Method
Siamese (de la Loubere)

The square

12345
17241815
23571416
46132022
101219213
11182529
How this was calculated
  1. For an order of 5, which is odd, the square is built by a rule: odd orders by the Siamese method, multiples of four by swapping cells on a diagonal pattern, and the other even orders by Strachey's method.
  2. The magic constant is n x (2 x first + (n^2 - 1) x step) / 2 = 5 x (2 x 1 + 24 x 1) / 2 = 65.
  3. Every row, every column and both main diagonals are checked to give that constant before the square is shown.

Calculated using SumPanda.com · https://sumpanda.com/magic-square-generator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the magic square generator

  1. Enter the order of the square, a whole number from 3 to 16. A square of order 5 has 5 rows and 5 columns.
  2. Optionally open the advanced options to change the first number and the step between numbers. The classic square starts at 1 with a step of 1.
  3. Read the magic constant, the total that every row, column and diagonal has.
  4. Study the grid, and copy it or download it as a CSV file.

Formula

magic constant = n x (2 x first + (n^2 - 1) x step) / 2

for the classic square (first 1, step 1) the constant is n x (n^2 + 1) / 2

odd orders use the Siamese method; multiples of 4 use a complement pattern; other even orders use Strachey's method

The numbers are first + step x k for k from 0 to n^2 - 1, each used once. Every row, column and both main diagonals are added up and checked before the square is shown.

Squares of order 3, 4, 5 and 6

The order 3 square is 8 1 6 / 3 5 7 / 4 9 2 with a constant of 15. Order 4 has a constant of 34, order 5 has 65 (its first row is 17 24 1 8 15), order 6 has 111 and order 10 has 505. The formula gives 5 x 26 / 2 = 65 for order 5.

With a first number of 10 and a step of 2, the order 3 square uses 10, 12, 14 up to 26, and its constant is 3 x (20 + 8 x 2) / 2 = 54. The tests confirmed that every order from 3 to 40 gives a square whose rows, columns and diagonals all add to the constant, and that a square with two numbers swapped is rejected.

How the squares are built

For odd orders, the Siamese method places 1 in the top middle cell and moves up and to the right for each next number, dropping down a row when the cell is taken. For multiples of four, a pattern of diagonals marks the cells whose numbers are replaced by their complement. For orders that are even but not multiples of four, the order is split into four quarters, each a magic square of half the order, and then some cells are swapped.

Order 2 and other limits

No magic square of order 2 exists, so the tool starts at 3. It stops at 16 to keep the grid readable on a screen. Magic squares are not unique, and many other squares exist for each order; this tool gives one of them. For other puzzles, try the Sudoku Generator or the Pascal Triangle Generator.

More tools for playing with numbers

For more number patterns and conversions, try the Pythagorean Triples Generator, Collatz Sequence Calculator and Egyptian Fraction Decomposer.

Assumptions and limits

  • The square is a normal magic square: every row, column and both main diagonals add to the same total.
  • Each number appears exactly once.
  • The order is a whole number from 3 to 16.
  • The first number can be negative, and the step must be a whole number of at least 1.
  • The order in the form is an example. Try your own.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Is there only one magic square of each order?

No. For order 3 there is one square apart from turning and flipping it, but the number grows fast: order 4 has 880 and larger orders have far more. The tool gives one.

What is a magic constant?

It is the total that each row, column and main diagonal adds up to. For the numbers 1 to n squared it equals n times (n squared plus 1), divided by 2.

Why is there no square of order 2?

The four numbers 1 to 4 cannot be arranged so that both rows, both columns and both diagonals share a total, so no square of order 2 exists.

Can the squares use other numbers than 1 to n squared?

Yes, as long as the numbers are equally spaced. The first number and step in the advanced options give a square built from first + step times 0, 1, 2, and so on.