Magic squares are numbers arranged in a square array such that the numbers in each row, column and main diagonal add up to the same number, known as the magic constant. An example is the 3by3 square below:
8 
1 
6 
1 
5 
7 
4 
9 
2 
In this square, the numbers in each row, column and main diagonal add up to fifteen. Apart from rotations and reflections, the square is a unique solution for its size.
Magic squares have been held as sacred and worshipped in many ancient cultures. The Chinese were the first to discover magic squares. A legend says that Emperor Yü saw a tortoise climb out of the Luo River with the 3by3 magic square inscribed on its shell. Chinese then have since called magic squares luoshu. Muslims too found magic squares interesting. They liked 5by5 squares with 1 at their centre, as they believed it represented the unity and centrality of Allah. The space with the central 1 was often respectfully left blank. Many western mathematicians were also interested in magic squares later. One of the most famous was Benjamin Franklin, who could construct them quickly.
There are 880 4by4 magic squares. The most famous one is pictured below.
16 
3 
2 
13 
5 
10 
11 
8 
9 
6 
7 
12 
4 
15 
14 
1 
This square was discovered by Albretch Dürer, and is pictured in his engraving Melancolia. The most striking thing about it is that the year of its completion, 1514, is embedded in the bottom row of the square. It is believed that Dürer started with these two numbers and worked the rest of the square out through trialanderror.
The square has many other properties. The four corner squares, as well as the four centre squares, for instance, sum to the magic constant of 34. The four squares in each corner also sum to 34.
In 1973, Richard Schroeppel calculated the number of 5by5 magic squares. Excluding rotations and reflections, the total number of 5by5 magic squares is
275 305 224. If, however, squares obtained by exchanging rows and columns of an existing square, and by subtracting the number in each cell from the total number of cells, and adding one, are eliminated, the total number of magic squares drops to
36 798 121.
An exceptional 5by5 magic square is pictured below.
1 
15 
24 
8 
17 
23 
7 
16 
5 
14 
20 
4 
13 
22 
6 
12 
21 
10 
19 
3 
9 
18 
2 
11 
25 
This square is both associative, meaning that numbers opposite each other add up to a constant, and pandiagonal, meaning that broken diagonals add up to the magic constant also. 4by4 magic squares can be either pandiagonal or associative (the one pictured above is associative), but not both. Of the 5by5 squares, only sixteen are both pandiagonal and associative. Another two are shown below.
10 
18 
1 
14 
22 
2 
23 
19 
15 
66 

11 
24 
7 
20 
3 
14 
10 
1 
22 
18 

17 
5 
13 
21 
9 
21 
17 
13 
9 
5 

23 
6 
19 
2 
15 
8 
4 
25 
16 
12 

4 
12 
2 
8 
16 
20 
11 
7 
3 
24 
Some magic squares have the property that when every number in it is squared, the rows, columns and diagonals still add up to the same number. One example is shown below.
47 
28 
6 
49 
23 
36 
62 
9 
8 
51 
45 
26 
64 
11 
21 
34 
53 
2 
32 
43 
13 
58 
40 
19 
30 
41 
55 
4 
38 
17 
15 
60 
42 
29 
3 
56 
18 
37 
59 
16 
1 
54 
44 
31 
57 
14 
20 
39 
52 
7 
25 
46 
12 
63 
33 
22 
27 
48 
50 
5 
35 
24 
10 
61 
Other families of magic squares include those with prime numbers. An example is the one below:
67 
1 
43 
13 
37 
61 
31 
73 
7 
The smallest known 3by3 magic square with consecutive prime numbers was discovered by Harry Nelson, in response to a challenge from Martin Gardner. It is shown below.
1 480 028 141 
1 480 028 213 
1 480 028 159 
1 480 028 189 
1 480 028 171 
1 480 028 153 
1 480 028 183 
1 480 028 129 
1 480 028 201 