Magic square

From Academic Kids

In mathematics, a magic square of order n is an arrangement of n² numbers in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same constant. A normal magic square contains the integers from 1 to n².

Magic squares exist for all orders n ≥ 1 except n = 2, although the case n = 1 is trivial—it consists of a single cell containing the number 1. The smallest nontrivial case, shown below, is of order 3.

Missing image

The constant sum in every row, column and diagonal is called the magic constant, M. The magic constant of a normal magic square depends only on n and has the value

<math>M(n) = \frac{n(n^2+1)}{2}<math>

For normal magic squares of order n = 3, 4, 5, …, the magic constants (sequence A006003 in OEIS) are:

15, 34, 65, 111, 175, 260, …

Brief history of magic squares

The Lo Shu Square (3x3 magic square)

Chinese literature dating from as early as 2800 BC tells the legend of Lo Shu or "scroll of the river Lo": in ancient China, there was a huge flood. The people tried to offer some sacrifice to the river god of one of the flooding rivers, the Lo river, to calm his anger. Then, there emerged from the water a turtle with a curious figure/pattern on its shell; there were circular dots of numbers that were arranged in a three by three nine-grid pattern such that the sum of the numbers in each row, column and diagonal was the same: 15. This number is also equal to the 15 days in each of the 24 cycles of the Chinese solar year. This pattern, in a certain way, helped in controlling the river.

Missing image

The Lo Shu Square, as the magic square on the turtle shell is called, is the unique normal magic square of order three.

The early squares of order four (4x4 magic squares)

The earliest magic square of order four was found inscribed Khajuraho, India, dating from the eleventh or twelfth century; it is also a so-called diabolic or panmagic (pandiagonal magic square) where, in addition to the rows, columns and main diagonals, the broken diagonals also have the same sum.

Yang Hui, in the 13th-century China, was one of the first mathematicians to study magic squares, or vertical and horizontal diagrams as they were called. He created several magic squares, including 4th order ones [1] (

Cultural significance of magic squares

Magic Squares have fascinated humanity throughout the ages, and have been around for over 4,000 years. They were frequently found in a number of cultures, including Egypt and India, engraved on stone or metal and worn as talismans, the belief being that magic squares had astrological and divinatory qualities, their usage ensuring longevity, and prevention against diseases.

The Kubera-Kolam is a floor painting used in India which is in the form of a magic square of order three. It is essentially the same as the Lo Shu Square, but with 19 added to each number, giving a magic constant of 72.

Missing image

The magic square figures in Greek writings dating from about 1300 BC and was used by Arabian astrologers in the ninth century when drawing up horoscopes.

Albrecht Drer's magic square

The order-4 magic square in Albrecht Drer's engraving Melancholia I is believed to be the first seen in European art. It is very similar to Yang Hui's square, created in China about 250 years before Drer's times. The sum 34 can be found in the rows, columns, diagonals, any 22 block of numbers, the sum of the four corners, the sums of the four outer numbers clockwise from the corners (3+8+14+9) and likewise the four counter-clockwise (the locations of four queens in the two solutions of 4-queens-puzzle[2] (, the two sets of four symmetrical numbers (2+8+9+15 and 3+5+12+14) and the sum of the middle two entries of the two outer columns and rows (e.g. 5+9+8+12), as well as several kite-shaped quartets, e.g. 3+5+11+15; the two numbers in the middle of the bottom row give the date of the engraving: 1514.

Missing image

The Sagrada Famlia magic square

Missing image
A magic square in architecture

The Passion faade of the Sagrada Famlia church in Barcelona, designed by sculptor Josep Subirachs, features a 44 magic square:

Missing image

The magic sum of the square is 33, the age of Jesus at the time of the Passion. Structurally, it is very similar to the Melancholia magic square, but it has had the numbers in four of the cells reduced by 1.

Types of magic squares and their construction

There are many ways to construct magic squares, but the standard (and most simple) way is to follow certain configurations / formulas which generate regular patterns. Magic squares exist for all values of n, with only one exception - it is impossible to construct a magic square of order 2. Magic squares can be classified into three types: odd, doubly even (n divisible by four) and singly even (n even, but not divisible by four). Odd and doubly even magic squares are easy to generate; the construction of singly even magic squares is more difficult but several methods exist, including the LUX method for magic squares (due to John Conway) and the Strachey method for magic squares. Only odd and doubly even magic squares are discussed below.

A method for constructing a magic square of odd order

Starting from the central column of the last row with the number 1, the fundamental movement for filling the squares is diagonally down and right, one step at a time. If a filled square is encountered, one moves vertically up one square, then continuing as before. When a move would leave the square, it is wrapped around to the first row or last column, respectively.

The same pattern can be achieved starting from the central column of the first row; In this case the fundamental movement is diagonally up and left, one step at a time, and if a filled square is encountered, one moves vertically down one square, then continuing as before. When a move would leave the square, it is wrapped around the last row or first column, respectively.

Similar patterns can also be obtained by starting from other squares.

Missing image

Missing image

Missing image

Order 3 Order 5 Order 9

A method of constructing a magic square of doubly even order

All the numbers are written in order from right to left across each row in turn, starting from the top right hand corner. Numbers are then either retained in the same place or interchanged with their diametrically opposite numbers in a certain regular pattern. In the magic square of order four, the numbers in the four central squares and one square at each corner are retained in the same place and the others are interchanged with their diametrically opposite numbers. In the magic square of order eight, the same is done; the 16 central squares and 4 squares at each corner are retained in their places and the rest are switched.

A general rule: If n represents the order of the doubly even square, retain numbers in the following pattern. The central square with sides of length n/2 should be retained. Also retain the squares with sides of length n/4 in each of the four corners.

Missing image

Order 8

Counting magic squares

Counting the number of distinct normal magic squares is a difficult problem in combinatorics. Squares that differ trivially by a rotation or a reflection are considered equivalent and are counted just as one. Even so, the count increases rapidly with n. In fact, non-trivial exact results are known only for n = 4 and n = 5. The magic square count is sequence A006052 in OEIS.

 order  count  details
3 1  The Lo Shu Square.
4 880  Frénicle de Bessy (1693).
5 275305224  Richard Schroeppel (1973).
6  (1.7745 ± 0.0016) × 1019   Klaus Pinn and C. Wieczerkowski (1998),
 through Monte Carlo simulation.
7  (3.7982 ± 0.0004) × 1034 


Extra constraints

Certain extra restrictions can be imposed on magical squares. If not only the main diagonals but also the broken diagonals sum to the magic constant, the result is a panmagic square. If raising each number to certain powers yields another magic square, the result is a bimagic, a trimagic, or, in general, a multimagic square.

Different constraints

Sometimes the rules for magic squares are relaxed, so that only the rows and columns but not necessarily the diagonals sum to the magic constant. In heterosquares and antimagic squares, the 2n + 2 sums must all be different.

Other operations

Instead of adding the numbers in each row, column and diagonal, one can apply some other operation. For example, a multiplicative magic square has a constant product of numbers.

Missing image

M = 216 M = 6720

Other magic shapes

Other shapes than squares can be considered, resulting, for example, in magic stars and magic hexagons. Going up in dimension results in magic cubes, magic tesseracts and other magic hypercubes.

Combined extensions

One can combine two or more of the above extensions, resulting in such objects as multiplicative multimagic hypercubes. Little seems to be known about this subject.

Special case in 4x4

It is normal to get a sum of 34 in a 4x4 magic square. In late 1970s, a multi talented person by name Ramiah from Tamil Nadu demonstrated to generate a magic square with the sum of rows/columns being 35. He would drop 13 from the sequence to achieve this result. The same format can be used to generate magic square with sum of 36 and 37 as well by dropping 9 & 5 correspondingly. Interestingly, this magic square had lots of symmetries noted in [3] (

M = 35

Related problems

n-Queens problem

Paul Muljadi discovered and proved that the n queens problem is related to magic squares because the magic constant of the n queens problem is also the order-n magic constant M(n) for n > 3.[4] (

In 1992, Demirrs, Rafraf, and Tanik published a method for converting some magic squares into N-queens solutions, and vice versa.

See also

External links


  • W. S. Andrews, Magic Squares and Cubes. (New York: Dover, 1960), originally printed in 1917
  • John Lee Fults, Magic Squares. (La Salle, Illinois: Open Court, 1974).
  • Cliff Pickover, The Zen of Magic Squares, Circles, and Stars (Princeton, New Jersey: Princeton University Press)de:Magisches Quadrat

es:Cuadrado mgico fr:Carr magique io:Magiala quadrato ja:魔方陣 he:ריבוע קסם it:Quadrato magico nl:Magisch vierkant pl:Kwadrat magiczny sl:magični kvadrat th:จัตุรัสกล zh:幻方


Academic Kids Menu

  • Art and Cultures
    • Art (
    • Architecture (
    • Cultures (
    • Music (
    • Musical Instruments (
  • Biographies (
  • Clipart (
  • Geography (
    • Countries of the World (
    • Maps (
    • Flags (
    • Continents (
  • History (
    • Ancient Civilizations (
    • Industrial Revolution (
    • Middle Ages (
    • Prehistory (
    • Renaissance (
    • Timelines (
    • United States (
    • Wars (
    • World History (
  • Human Body (
  • Mathematics (
  • Reference (
  • Science (
    • Animals (
    • Aviation (
    • Dinosaurs (
    • Earth (
    • Inventions (
    • Physical Science (
    • Plants (
    • Scientists (
  • Social Studies (
    • Anthropology (
    • Economics (
    • Government (
    • Religion (
    • Holidays (
  • Space and Astronomy
    • Solar System (
    • Planets (
  • Sports (
  • Timelines (
  • Weather (
  • US States (


  • Home Page (
  • Contact Us (

  • Clip Art (
Personal tools