Britannica Sources used in this answer

How do magic squares work?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

A magic square is a square matrix filled with numbers or letters arranged in a specific pattern. While historical examples like the SATOR square used words, the term most commonly refers to numerical grids used in number theory and recreational mathematics.1

In an arithmetical magic square, integers are placed in cells such that the sum of the numbers in every row, every column, and both main diagonals is identical; this total is known as the constant. A standard magic square of order n typically contains the sequence of natural numbers from 1 to n2.12

To construct one, a natural square—where numbers are simply listed in order—is often used as a starting point, though it lacks the "magical" property of a constant sum. By rearranging these numbers within the grid, the constant sum is achieved. For example, a 3 × 3 magic square uses the numbers 1 through 9 to produce a constant sum of 15.1