Skip to content
Omnikalc

Magic square constant calculator: the sum of every row, column and diagonal

Enter the size of the square, and optionally the first number and the step, to get the magic constant and the sum of all the numbers.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Results

Magic constant (sum of every row, column and diagonal)

65.00

Sum of all the numbers in the square
325.00
Largest number used
25.00
Average number (center value for odd n)
13.00

Magic squares have fascinated people for thousands of years, from ancient China to Dürer’s engraving Melencolia I. The magic square constant calculator takes the size, the first number and the step, and gives the magic constant, the sum of all the numbers, the largest number and the average.

How the calculation works

  • Enter the side n of the square, the first number a and the step d. The classic square uses the numbers 1 to n², which means a = 1 and d = 1.
  • The square holds the n² numbers a, a + d, a + 2d, …, a + (n² − 1)d, and each is used once.
  • The sum of all the numbers is n² × (first + last) ÷ 2. In a magic square, the n rows all have the same sum, so the magic constant is that total ÷ n.
  • For the numbers 1 to n², the constant is n × (n² + 1) ÷ 2. For an odd n, the average number sits at the center cell.

Example

A 5 × 5 magic square uses the numbers 1 to 25. The sum of all numbers is 25 × (1 + 25) ÷ 2 = 325, so each row, column and diagonal adds up to 325 ÷ 5 = 65. The largest number is 25, and the center cell of a classic 5 × 5 square holds the average, 13.

Why it matters

Puzzle makers, teachers and students use the constant to check a square quickly, and to know the target sum before filling in the cells. It is also a clean example of arithmetic series.

Good to know

The constant tells you what each line must add up to, but it does not build the square or prove one exists for the numbers you chose. Using steps that are not whole numbers gives constants that are not whole numbers either.

The triangular numbers calculator covers the sums of consecutive integers, and the arithmetic series calculator handles sums of any equally spaced list.

Frequently asked questions

What is a magic square?

A magic square is a grid of different numbers in which every row, column and the two main diagonals add up to the same value, the magic constant. The best known uses the whole numbers from 1 to n² with n rows and columns.

How do you compute the magic constant?

Add up all the numbers in the square and divide by n, because the n rows share that total equally. For the numbers 1 to n², the formula simplifies to n × (n² + 1) ÷ 2, which gives 15 for n = 3, 34 for n = 4 and 65 for n = 5.

Does a magic square exist for every size?

Squares exist for every size from 3 onwards. There is no 2 × 2 magic square with different numbers. Different methods build them for odd sizes, for sizes divisible by 4 and for sizes that are twice an odd number.

What if the numbers do not start at 1?

The constant also works for any arithmetic sequence. A square built from a, a + d, a + 2d and so on has a constant of n × (2a + (n² − 1)d) ÷ 2. Adding a number to every cell, or multiplying all of them, keeps the square magic.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.