Magic constant formula: n(n²+1)/2 explained

Last updated · By Perfect Magic Squares

For a normal n × n magic square, the sum of every row, column and main diagonal is the magic constant M = n(n² + 1) / 2 Both Wikipedia and MathWorld give this formula. "Normal" means the square uses each whole number from 1 to n² exactly once. The reason is short: the grid holds a fixed total, and the n rows share it equally.

Engraved 4 by 4 grid of numbers from Dürer's Melencolia I: 16, 3, 2, 13 across the top row and 4, 15, 14, 1 along the bottom
The magic square in Albrecht Dürer's engraving Melencolia I. Public domain, via Wikimedia Commons.

Why the formula works

There are two steps: add up every number in the grid, then divide that total among the rows.

Step 1: the total of 1 to n². Write N for the largest number, so N = n². Call the total S = 1 + 2 + … + N. Write the same sum again backwards and add the two lines column by column:

S = 1 + 2 + … + N
S = N + (N − 1) + … + 1

Each column adds to N + 1, and there are N columns, so 2S = N(N + 1). Putting N = n² back in gives

S = n²(n² + 1) / 2

Step 2: split it over the rows. A normal magic square uses each of those numbers once, so the whole grid adds to S. The grid has n rows, and each row must add to the same constant M. Then n × M = S, and dividing by n leaves

M = n(n² + 1) / 2

Columns work the same way, since they also split the grid into n equal-sum pieces. The diagonals are not needed for the argument. They are an extra condition the square must still meet, and the formula tells you what sum to aim for.

Magic constant for 3 × 3 up to 12 × 12

These values are the formula applied to each n. Each is a whole number: when n is odd, n² + 1 is even, and when n is even, n itself is even, so the product n(n² + 1) always halves cleanly.

Magic constant M = n(n² + 1) / 2 for normal squares of order 3 to 12.
Order (n × n)Numbers usedMagic constant M
3 × 31 to 915
4 × 41 to 1634
5 × 51 to 2565
6 × 61 to 36111
7 × 71 to 49175
8 × 81 to 64260
9 × 91 to 81369
10 × 101 to 100505
11 × 111 to 121671
12 × 121 to 144870

The first few terms also appear in the Online Encyclopedia of Integer Sequences, which lists the constants for squares numbered 1 through n². This is the only table of constants on the site, and other pages link here rather than repeat it. To get M for a specific n, use the magic square generator on the home page.

One 3 × 3 and one 4 × 4 check

For n = 3: M = 3 × (9 + 1) / 2 = 3 × 10 / 2 = 15. The numbers 1 to 9 add to 45, and 45 split over three rows is 15 each. The 3x3 magic square guide shows the only 3x3 square, up to rotation and reflection, that reaches it.

For n = 4: M = 4 × (16 + 1) / 2 = 4 × 17 / 2 = 34. The square in the engraving above reads 16, 3, 2, 13 across its top row, and 16 + 3 + 2 + 13 = 34. Its second row is 5 + 10 + 11 + 8 = 34 as well. The 4x4 magic square guide covers how many such squares there are and how to build one.

The same formula gives the constant for every order in the table above, including the one covered in the 5x5 magic square guide.

A two-step hand check for any grid

Step 1: the numbers. Confirm that 1 to n² each appear exactly once. If any number is missing or repeated, the grid is not normal and M = n(n² + 1) / 2 does not apply to it. Shortcut: add all the cells. If the total is not n²(n² + 1) / 2, no choice of rows can all equal M, so stop here.

A 3 × 3 grid whose cells total 46 averages 46 / 3 per row, which is not 15, so it fails at once.

Step 2: the lines. Add every row, every column and both main diagonals, and compare each with M. All of them must match. A correct total does not guarantee this, so Step 2 is still needed.

When a grid is partly filled in, the magic square solver does the line checks and lists every way to finish it.

What the formula does not cover

A square that does not use exactly the numbers 1 to n² is not normal, and n(n² + 1) / 2 does not apply to it. Such squares have their own constants, which depend on the numbers chosen and are outside the scope of this page.

Report an error