Structure preview

A 4×4 magic square with your chosen sum

Two constructions for a 4×4 magic square with any integer sum: the formula 21a+b and a transformation of the normal square with sum 34.

Section: Algebra Updated:
Articles /birthday-gift-magic-square
A 4×4 magic square with your chosen sum

6 min

Can we freely choose an integer sum S and build a 4×4 magic square? Yes, but we must distinguish the essential property — every row, column and main diagonal sums to S — from additional properties such as having sixteen positive, distinct entries. The interactive laboratory compares two constructions and verifies all ten lines before displaying a result.

First method: S = 21a + b

The existing parametric method writes S = 21a + b and fills the sixteen cells as follows:

a+b    a      12a    7a
11a    8a     b      2a
5a     10a    3a     3a+b
4a     2a+b   6a     9a

The four rows, four columns and two diagonals all sum to 21a+b. Usually we may take a=floor(S/21) and b=S−21a. For 1≤S≤21 the laboratory adjusts the choice to avoid zero cells: a=1 for S from 1 to 17, a=2 for S from 18 to 21, and b may be negative. At S=34, a=1 and b=13, giving each integer from 1 through 16 exactly once.

Second method: transform a normal square

Start from this square, containing each integer from 1 to 16 once:

 8  11  14   1
13   2   7  12
 3  16   9   6
10   5   4  15

Every row, column and diagonal sums to 34. The special numbers 13, 14, 15 and 16 are placed so that each of these ten lines contains exactly one of them. This positional property explains the transformation.

Distribute the difference

Compute D=S−34 and use Euclidean division by 4: D=4q+r, with 0≤r<4 even when D is negative. Add q to each of the twelve ordinary cells, and q+r to each of the four special cells. Every line then gains 3q+(q+r)=4q+r=D, so its new sum is 34+D=S.

Three positive examples and one below 34

For S=67, D=33=4×8+1: the increments are 8 and 9. The result is:

16  19  23   9
22  10  15  20
11  25  17  14
18  13  12  24

For S=82, D=48=4×12+0: every cell receives 12:

20  23  26  13
25  14  19  24
15  28  21  18
22  17  16  27

For S=85, D=51=4×12+3: the increments are 12 and 15:

20  23  29  13
28  14  19  24
15  31  21  18
22  17  16  30

We need not impose S≥34. If S=7, then D=−27=4(−7)+1 and the increments are −7 and −6:

 1   4   8  −6
 7  −5   0   5
−4  10   2  −1
 3  −2  −3   9

All ten lines sum to 7 and the sixteen entries remain distinct. They cannot all be positive: their total would be 4×7=28, whereas the least possible sum of sixteen distinct positive integers is 1+2+⋯+16=136.

Further configurations that stay magic

In the starting square, the top-left 2×2 block, central 2×2 block, bottom-right 2×2 block and four corners also sum to 34. Each contains exactly one special number, so after transformation each sums to S. The laboratory checks these properties and displays them only when valid.

A square whose sum is connected to a birthday date can make a mathematical gift, but this is only one possible use. Try both methods in the laboratory →

Source of inspiration for the second method: Arthur Benjamin and Michael Shermer, Secrets of Mental Math: The Mathemagician’s Guide to Lightning Calculation and Amazing Math Tricks, “Magic Squares” section, pp. 206–209 of the cited edition. The present text and checks are original.