In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, especially
historical
History is the systematic study of the past, focusing primarily on the human past. As an academic discipline, it analyses and interprets evidence to construct narratives about what happened and explain why it happened. Some theorists categ ...
and
recreational mathematics
Recreational mathematics is mathematics carried out for recreation (entertainment) rather than as a strictly research-and-application-based professional activity or as a part of a student's formal education. Although it is not necessarily limited ...
, a square array of numbers, usually
positive integer
In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positiv ...
s, is called a magic square if the sums of the numbers in each row, each column, and both main diagonals are the same. The "order" of the magic square is the number of integers along one side (''n''), and the constant sum is called the "
magic constant". If the array includes just the positive integers
, the magic square is said to be "normal". Some authors take "magic square" to mean "normal magic square".
Magic squares that include repeated entries do not fall under this definition and are referred to as "trivial". Some well-known examples, including the
Sagrada Família magic square and the
Parker square
In mathematics, especially History of mathematics, historical and recreational mathematics, a square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row, each column, and both main diago ...
, are trivial in this sense. When all the rows and columns but not both diagonals sum to the magic constant, this gives a semimagic square (sometimes called orthomagic square).
The mathematical study of a magic square typically deals with its construction, classification, and enumeration. Although completely general methods for producing all the magic squares of all orders do not exist, historically three general techniques have been discovered: the bordering method, by making composite magic squares, and by adding two preliminary squares. There are also more specific strategies like the continuous enumeration method that reproduces specific patterns. Magic squares are generally classified according to their order ''n'' as: odd if ''n'' is odd, evenly even (also referred to as "doubly even") if ''n'' is a multiple of 4, oddly even (also known as "singly even") if ''n'' is any other even number. This classification is based on different techniques required to construct odd, evenly even, and oddly even squares. Beside this, depending on further properties, magic squares are also classified as
associative magic squares,
pandiagonal magic square
A pandiagonal magic square or panmagic square (also diabolic square, diabolical square or diabolical magic square) is a magic square with the additional property that the broken diagonals, i.e. the diagonals that wrap round at the edges of the squ ...
s,
most-perfect magic square
A most-perfect magic square of order ''n'' is a magic square containing the numbers 1 to ''n''2 with two additional properties:
# Each 2 × 2 subsquare sums to 2''s'', where .
# All pairs of integers distant ''n''/2 along a (major) diagonal su ...
s, and so on. More challengingly, attempts have also been made to classify all the magic squares of a given order as transformations of a smaller set of squares. Except for ''n'' ≤ 5, the enumeration of higher-order magic squares is still an open challenge. The enumeration of most-perfect magic squares of any order was only accomplished in the late 20th century.
Magic squares have a long history, dating back to at least 190 BCE in China. At various times they have acquired occult or mythical significance and have appeared as symbols in works of art. In modern times they have been generalized a number of ways, including using extra or different constraints, multiplying instead of adding cells, using alternate shapes or more than two dimensions, and replacing numbers with shapes and addition with geometric operations.
History
The third-order magic square was known to Chinese mathematicians as early as 190 BCE, and explicitly given by the first century of the common era.
The first dateable instance of the fourth-order magic square occurred in 587 CE in India.
Specimens of magic squares of order 3 to 9 appear in an encyclopedia from
Baghdad
Baghdad ( or ; , ) is the capital and List of largest cities of Iraq, largest city of Iraq, located along the Tigris in the central part of the country. With a population exceeding 7 million, it ranks among the List of largest cities in the A ...
, the ''
Encyclopedia of the Brethren of Purity
The ''Encyclopedia of the Brethren of Purity'' (, Rasā'il Ikhwān al-ṣafā') also variously known as the ''Epistles of the Brethren of Sincerity'', ''Epistles of the Brethren of Purity'' and ''Epistles of the Brethren of Purity and Loyal Frien ...
'' (''Rasa'il Ikhwan al-Safa'').
By the end of the 12th century, the general methods for constructing magic squares were well established.
Around this time, some of these squares were increasingly used in conjunction with magic letters, as in
Shams Al-ma'arif, for occult purposes. In India, all the fourth-order pandiagonal magic squares were enumerated by Narayana in 1356. Magic squares were made known to Europe through translation of Arabic sources as occult objects during the Renaissance, and the general theory had to be re-discovered independent of prior developments in China, India, and Middle East. Also notable are the ancient cultures with a tradition of mathematics and numerology that did not discover the magic squares: Greeks, Babylonians, Egyptians, and Pre-Columbian Americans.
Chinese

While ancient references to the pattern of even and odd numbers in the 3×3 magic square appear in the ''
I Ching
The ''I Ching'' or ''Yijing'' ( ), usually translated ''Book of Changes'' or ''Classic of Changes'', is an ancient Chinese divination text that is among the oldest of the Chinese classics. The ''I Ching'' was originally a divination manual in ...
'', the first unequivocal instance of this magic square appears in the chapter called ''Mingtang'' (Bright Hall) of a 1st-century book ''Da Dai Liji'' (Record of Rites by the Elder Dai), which purported to describe ancient Chinese rites of the Zhou dynasty.
These numbers also occur in a possibly earlier mathematical text called ''Shushu jiyi'' (Memoir on Some Traditions of Mathematical Art), said to be written in 190 BCE. This is the earliest appearance of a magic square on record; and it was mainly used for divination and astrology.
The 3×3 magic square was referred to as the "Nine Halls" by earlier Chinese mathematicians.
The identification of the 3×3 magic square to the legendary Luoshu chart was only made in the 12th century, after which it was referred to as the Luoshu square.
The oldest surviving Chinese treatise that displays magic squares of order larger than 3 is
Yang Hui's ''Xugu zheqi suanfa'' (Continuation of Ancient Mathematical Methods for Elucidating the Strange) written in 1275.
The contents of Yang Hui's treatise were collected from older works, both native and foreign; and he only explains the construction of third and fourth-order magic squares, while merely passing on the finished diagrams of larger squares.
He gives a magic square of order 3, two squares for each order of 4 to 8, one of order nine, and one semi-magic square of order 10. He also gives six magic circles of varying complexity.
The above magic squares of orders 3 to 9 are taken from Yang Hui's treatise, in which the Luo Shu principle is clearly evident.
The order 5 square is a bordered magic square, with central 3×3 square formed according to Luo Shu principle. The order 9 square is a composite magic square, in which the nine 3×3 sub squares are also magic.
After Yang Hui, magic squares frequently occur in Chinese mathematics such as in Ding Yidong's ''Dayan suoyin'' (),
Cheng Dawei's ''
Suanfa tongzong'' (1593), Fang Zhongtong's ''Shuduyan'' (1661) which contains magic circles, cubes and spheres, Zhang Chao's ''Xinzhai zazu'' (), who published China's first magic square of order ten, and lastly Bao Qishou's ''Binaishanfang ji'' (), who gave various three dimensional magic configurations.
However, despite being the first to discover the magic squares and getting a head start by several centuries, the Chinese development of the magic squares are much inferior compared to the Indian, Middle Eastern, or European developments. The high point of Chinese mathematics that deals with the magic squares seems to be contained in the work of Yang Hui; but even as a collection of older methods, this work is much more primitive, lacking general methods for constructing magic squares of any order, compared to a similar collection written around the same time by the Byzantine scholar
Manuel Moschopoulos.
This is possibly because of the Chinese scholars' enthralment with the Lo Shu principle, which they tried to adapt to solve higher squares; and after Yang Hui and the fall of
Yuan dynasty
The Yuan dynasty ( ; zh, c=元朝, p=Yuáncháo), officially the Great Yuan (; Mongolian language, Mongolian: , , literally 'Great Yuan State'), was a Mongol-led imperial dynasty of China and a successor state to the Mongol Empire after Div ...
, their systematic purging of the foreign influences in Chinese mathematics.
Japan
Japan and China have similar mathematical traditions and have repeatedly influenced each other in the history of magic squares. The Japanese interest in magic squares began after the dissemination of Chinese works—Yang Hui's ''Suanfa'' and Cheng Dawei's ''Suanfa tongzong''—in the 17th century, and as a result, almost all the ''
wasans'' devoted their time to its study.
In the 1660 edition of ''Ketsugi-sho'', Isomura Kittoku gave both odd and even ordered bordered magic squares as well as magic circles; while the 1684 edition of the same book contained a large section on magic squares, demonstrating that he had a general method for constructing bordered magic squares.
In ''Jinko-ki'' (1665) by Muramatsu Kudayu Mosei, both magic squares and magic circles are displayed. The largest square Mosei constructs is of 19th order. Various magic squares and magic circles were also published by Nozawa Teicho in ''Dokai-sho'' (1666), Sato Seiko in ''Kongenki'' (1666), and Hosino Sanenobu in ''Ko-ko-gen Sho'' (1673).
One of
Seki Takakazu's ''Seven Books'' (''Hojin Yensan'') (1683) is devoted completely to magic squares and circles. This is the first Japanese book to give a general treatment of magic squares in which the algorithms for constructing odd, singly even and doubly even bordered magic squares are clearly described.
In 1694 and 1695, Yueki Ando gave different methods to create the magic squares and displayed squares of order 3 to 30. A fourth-order magic cube was constructed by Yoshizane Tanaka (1651–1719) in ''Rakusho-kikan'' (1683). The study of magic squares was continued by Seki's pupils, notably by Katahiro Takebe, whose squares were displayed in the fourth volume of ''Ichigen Kappo'' by Shukei Irie, Yoshisuke Matsunaga in ''Hojin-Shin-jutsu'', Yoshihiro Kurushima in ''Kyushi Iko'' who rediscovered a method to produce the odd squares given by Agrippa,
and
Naonobu Ajima.
Thus by the beginning of the 18th century, the Japanese mathematicians were in possession of methods to construct magic squares of arbitrary order. After this, attempts at enumerating the magic squares was initiated by Nushizumi Yamaji.
India
The 3×3 magic square first appears in India in ''Gargasamhita'' by Garga, who recommends its use to pacify the nine planets (''navagraha''). The oldest version of this text dates from 100 CE, but the passage on planets could not have been written earlier than 400 CE. The first dateable instance of 3×3 magic square in India occur in a medical text ''Siddhayog'' () by Vrnda, which was prescribed to women in labor in order to have easy delivery.
The oldest dateable fourth order magic square in the world is found in an encyclopaedic work written by
Varahamihira around 587 CE called ''Brhat Samhita''. The magic square is constructed for the purpose of making perfumes using 4 substances selected from 16 different substances. Each cell of the square represents a particular ingredient, while the number in the cell represents the proportion of the associated ingredient, such that the mixture of any four combination of ingredients along the columns, rows, diagonals, and so on, gives the total volume of the mixture to be 18. Although the book is mostly about divination, the magic square is given as a matter of combinatorial design, and no magical properties are attributed to it. The special features of this magic square were commented on by Bhattotpala ()
The square of Varahamihira as given above has sum of 18. Here the numbers 1 to 8 appear twice in the square. It is a
pan-diagonal magic square. Four different magic squares can be obtained by adding 8 to one of the two sets of 1 to 8 sequence. The sequence is selected such that the number 8 is added exactly twice in each row, each column and each of the main diagonals. One of the possible magic squares shown in the right side. This magic square is remarkable in that it is a 90 degree rotation of a magic square that appears in the 13th century Islamic world as one of the most popular magic squares.
The construction of 4th-order magic square is detailed in a work titled ''Kaksaputa'', composed by the alchemist
Nagarjuna
Nāgārjuna (Sanskrit: नागार्जुन, ''Nāgārjuna''; ) was an Indian monk and Mahayana, Mahāyāna Buddhist Philosophy, philosopher of the Madhyamaka (Centrism, Middle Way) school. He is widely considered one of the most importa ...
around 10th century CE. All of the squares given by Nagarjuna are 4×4 magic squares, and one of them is called ''Nagarjuniya'' after him. Nagarjuna gave a method of constructing 4×4 magic square using a primary skeleton square, given an odd or even magic sum.
The Nagarjuniya square is given below, and has the sum total of 100.
The Nagarjuniya square is a
pan-diagonal magic square. The Nagarjuniya square is made up of two arithmetic progressions starting from 6 and 16 with eight terms each, with a common difference between successive terms as 4. When these two progressions are reduced to the normal progression of 1 to 8, the adjacent square is obtained.
Around 12th-century, a 4×4 magic square was inscribed on the wall of
Parshvanath temple in
Khajuraho, India. Several Jain hymns teach how to make magic squares, although they are undateable.
As far as is known, the first systematic study of magic squares in India was conducted by
Thakkar Pheru, a Jain scholar, in his ''Ganitasara Kaumudi'' (c. 1315). This work contains a small section on magic squares which consists of nine verses. Here he gives a square of order four, and alludes to its rearrangement; classifies magic squares into three (odd, evenly even, and oddly even) according to its order; gives a square of order six; and prescribes one method each for constructing even and odd squares. For the even squares, Pheru divides the square into component squares of order four, and puts the numbers into cells according to the pattern of a standard square of order four. For odd squares, Pheru gives the method using
horse move or knight's move. Although algorithmically different, it gives the same square as the De la Loubere's method.
The next comprehensive work on magic squares was taken up by
Narayana Pandit, who in the fourteenth chapter of his ''Ganita Kaumudi'' (1356) gives general methods for their construction, along with the principles governing such constructions. It consists of 55 verses for rules and 17 verses for examples. Narayana gives a method to construct all the pan-magic squares of fourth order using knight's move; enumerates the number of pan-diagonal magic squares of order four, 384, including every variation made by rotation and reflection; three general methods for squares having any order and constant sum when a standard square of the same order is known; two methods each for constructing evenly even, oddly even, and of squares when the sum is given. While Narayana describes one older method for each species of square, he claims the method of
superposition for evenly even and odd squares and a method of interchange for oddly even squares to be his own invention. The superposition method was later re-discovered by
De la Hire in Europe. In the last section, he conceives of other figures, such as circles, rectangles, and hexagons, in which the numbers may be arranged to possess properties similar to those of magic squares.
Below are some of the magic squares constructed by Narayana:
The order 8 square is interesting in itself since it is an instance of the most-perfect magic square. Incidentally, Narayana states that the purpose of studying magic squares is to construct ''yantra'', to destroy the ego of bad mathematicians, and for the pleasure of good mathematicians. The subject of magic squares is referred to as ''bhadraganita'' and Narayana states that it was first taught to men by god
Shiva
Shiva (; , ), also known as Mahadeva (; , , Help:IPA/Sanskrit, ɐɦaːd̪eːʋɐh and Hara, is one of the Hindu deities, principal deities of Hinduism. He is the God in Hinduism, Supreme Being in Shaivism, one of the major traditions w ...
.
Middle East, North Africa, Muslim Iberia

Although the early history of magic squares in Persia and Arabia is not known, it has been suggested that they were known in pre-Islamic times.
It is clear, however, that the study of magic squares was common in
medieval Islam, and it was thought to have begun after the introduction of
chess
Chess is a board game for two players. It is an abstract strategy game that involves Perfect information, no hidden information and no elements of game of chance, chance. It is played on a square chessboard, board consisting of 64 squares arran ...
into the region.
The first dateable appearance of a magic square of order 3 occurs in
Jābir ibn Hayyān's (fl. c. 721 – c. 815) ''Kitab al-mawazin al-Saghir'' (The Small Book of Balances) where the magic square and its related numerology is associated with alchemy.
While it is known that treatises on magic squares were written in the 9th century, the earliest extant treaties date from the 10th-century: one by
Abu'l-Wafa al-Buzjani () and another by Ali b. Ahmad al-Antaki ().
These early treatises were purely mathematical, and the Arabic designation for magic squares used is ''wafq al-a'dad'', which translates as ''harmonious disposition of the numbers''.
By the end of 10th century, the two treatises by Buzjani and Antaki makes it clear that the Middle Eastern mathematicians had understood how to construct bordered squares of any order as well as simple magic squares of small orders (''n'' ≤ 6) which were used to make composite magic squares.
A specimen of magic squares of orders 3 to 9 devised by Middle Eastern mathematicians appear in an encyclopedia from
Baghdad
Baghdad ( or ; , ) is the capital and List of largest cities of Iraq, largest city of Iraq, located along the Tigris in the central part of the country. With a population exceeding 7 million, it ranks among the List of largest cities in the A ...
, the
Rasa'il Ikhwan al-Safa (the ''
Encyclopedia of the Brethren of Purity
The ''Encyclopedia of the Brethren of Purity'' (, Rasā'il Ikhwān al-ṣafā') also variously known as the ''Epistles of the Brethren of Sincerity'', ''Epistles of the Brethren of Purity'' and ''Epistles of the Brethren of Purity and Loyal Frien ...
'').
The squares of order 3 to 7 from Rasa'il are given below:
The 11th century saw the finding of several ways to construct simple magic squares for odd and evenly even orders; the more difficult case of oddly even case (''n = 4k + 2'') was solved by
Ibn al-Haytham
Ḥasan Ibn al-Haytham (Latinization of names, Latinized as Alhazen; ; full name ; ) was a medieval Mathematics in medieval Islam, mathematician, Astronomy in the medieval Islamic world, astronomer, and Physics in the medieval Islamic world, p ...
with ''k'' even (c. 1040), and completely by the beginning of 12th century, if not already in the latter half of the 11th century.
Around the same time, pandiagonal squares were being constructed. Treaties on magic squares were numerous in the 11th and 12th century. These later developments tended to be improvements on or simplifications of existing methods. From the 13th century, magic squares were increasingly put to occult purposes.
However, much of these later texts written for occult purposes merely depict certain magic squares and mention their attributes, without describing their principle of construction, with only some authors keeping the general theory alive.
One such occultist was the Algerian
Ahmad al-Buni (c. 1225), who gave general methods on constructing bordered magic squares; some others were the 17th century Egyptian Shabramallisi and the 18th century Nigerian al-Kishnawi.
The magic square of order three was described as a child-bearing charm
since its first literary appearances in the alchemical works of
Jābir ibn Hayyān (fl. c. 721 – c. 815)
and
al-Ghazālī (1058–1111) and it was preserved in the tradition of the planetary tables. The earliest occurrence of the association of seven magic squares to the virtues of the seven heavenly bodies appear in Andalusian scholar
Ibn Zarkali's (known as Azarquiel in Europe) (1029–1087) ''Kitāb tadbīrāt al-kawākib'' (''Book on the Influences of the Planets'').
A century later, the Algerian scholar Ahmad al-Buni attributed mystical properties to magic squares in his highly influential book ''Shams al-Ma'arif'' (''The Book of the Sun of Gnosis and the Subtleties of Elevated Things''), which also describes their construction. This tradition about a series of magic squares from order three to nine, which are associated with the seven planets, survives in Greek, Arabic, and Latin versions. There are also references to the use of magic squares in astrological calculations, a practice that seems to have originated with the Arabs.
Latin Europe

Unlike in Persia and Arabia, better documentation exists of how the magic squares were transmitted to Europe. Around 1315, influenced by Arab sources, the Greek Byzantine scholar
Manuel Moschopoulos wrote a mathematical treatise on the subject of magic squares, leaving out the mysticism of his Middle Eastern predecessors, where he gave two methods for odd squares and two methods for evenly even squares. Moschopoulos was essentially unknown to the Latin Europe until the late 17th century, when Philippe de la Hire rediscovered his treatise in the Royal Library of Paris. However, he was not the first European to have written on magic squares; and the magic squares were disseminated to rest of Europe through Spain and Italy as occult objects. The early occult treaties that displayed the squares did not describe how they were constructed. Thus the entire theory had to be rediscovered.
Magic squares had first appeared in Europe in ''Kitāb tadbīrāt al-kawākib'' (''Book on the Influences of the Planets'') written by Ibn Zarkali of Toledo, Al-Andalus, as planetary squares by 11th century.
The magic square of three was discussed in numerological manner in early 12th century by Jewish scholar Abraham ibn Ezra of Toledo, which influenced later Kabbalists.
Ibn Zarkali's work was translated as ''Libro de Astromagia'' in the 1280s, due to
Alfonso X of Castille.
In the Alfonsine text, magic squares of different orders are assigned to the respective planets, as in the Islamic literature; unfortunately, of all the squares discussed, the Mars magic square of order five is the only square exhibited in the manuscript.
Magic squares surface again in Florence, Italy in the 14th century. A 6×6 and a 9×9 square are exhibited in a manuscript of the ''Trattato d'Abbaco'' (Treatise of the Abacus) by
Paolo Dagomari.
It is interesting to observe that Paolo Dagomari, like Pacioli after him, refers to the squares as a useful basis for inventing mathematical questions and games, and does not mention any magical use. Incidentally, though, he also refers to them as being respectively the Sun's and the Moon's squares, and mentions that they enter astrological calculations that are not better specified. As said, the same point of view seems to motivate the fellow Florentine
Luca Pacioli
Luca Bartolomeo de Pacioli, O.F.M. (sometimes ''Paccioli'' or ''Paciolo''; 1447 – 19 June 1517) was an Italian mathematician, Franciscan friar, collaborator with Leonardo da Vinci, and an early contributor to the field now known as account ...
, who describes 3×3 to 9×9 squares in his work ''De Viribus Quantitatis'' by the end of 15th century.
Europe after 15th century

The planetary squares had disseminated into northern Europe by the end of the 15th century.
For instance, the Cracow manuscript of ''
Picatrix'' from Poland displays magic squares of orders 3 to 9. The same set of squares as in the Cracow manuscript later appears in the writings of
Paracelsus
Paracelsus (; ; 1493 – 24 September 1541), born Theophrastus von Hohenheim (full name Philippus Aureolus Theophrastus Bombastus von Hohenheim), was a Swiss physician, alchemist, lay theologian, and philosopher of the German Renaissance.
H ...
in ''Archidoxa Magica'' (1567), although in highly garbled form. In 1514
Albrecht Dürer
Albrecht Dürer ( , ;; 21 May 1471 – 6 April 1528),Müller, Peter O. (1993) ''Substantiv-Derivation in Den Schriften Albrecht Dürers'', Walter de Gruyter. . sometimes spelled in English as Durer or Duerer, was a German painter, Old master prin ...
immortalized a 4×4 square in his famous engraving ''
Melencolia I.'' Paracelsus' contemporary
Heinrich Cornelius Agrippa von Nettesheim published his famous three volume book ''De occulta philosophia'' in 1531, where he devoted Chapter 22 of Book II to the planetary squares shown below.
The same set of squares given by Agrippa reappear in 1539 in ''Practica Arithmetice'' by
Girolamo Cardano
Gerolamo Cardano (; also Girolamo or Geronimo; ; ; 24 September 1501– 21 September 1576) was an Italian polymath whose interests and proficiencies ranged through those of mathematician, physician, biologist, physicist, chemist, astrologer, a ...
, where he explains the construction of the odd ordered squares using "diamond method", which was later reproduced by Bachet.
The tradition of planetary squares was continued into the 17th century by
Athanasius Kircher
Athanasius Kircher (2 May 1602 – 27 November 1680) was a German Society of Jesus, Jesuit scholar and polymath who published around 40 major works of comparative religion, geology, and medicine. Kircher has been compared to fellow Jes ...
in ''Oedipi Aegyptici'' (1653). In Germany, mathematical treaties concerning magic squares were written in 1544 by
Michael Stifel in'' Arithmetica Integra'', who rediscovered the bordered squares, and
Adam Riese, who rediscovered the continuous numbering method to construct odd ordered squares published by Agrippa. However, due to the religious upheavals of that time, these works were unknown to the rest of Europe.
In 1624 France,
Claude Gaspard Bachet described the "diamond method" for constructing Agrippa's odd ordered squares in his book ''Problèmes Plaisants''. During 1640
Bernard Frenicle de Bessy and
Pierre Fermat exchanged letters on magic squares and cubes, and in one of the letters Fermat boasts of being able to construct 1,004,144,995,344 magic squares of order 8 by his method.
An early account on the construction of bordered squares was given by
Antoine Arnauld
Antoine Arnauld (; 6 February 16128 August 1694) was a French Catholic theologian, priest, philosopher and mathematician. He was one of the leading intellectuals of the Jansenist group of Port-Royal and had a very thorough knowledge of patr ...
in his ''Nouveaux éléments de géométrie'' (1667). In the two treatise ''Des quarrez ou tables magiques'' and ''Table générale des quarrez magiques de quatre de côté'', published posthumously in 1693, twenty years after his death,
Bernard Frenicle de Bessy demonstrated that there were exactly 880 distinct magic squares of order four. Frenicle gave methods to construct magic square of any odd and even order, where the even ordered squares were constructed using borders. He also showed that interchanging rows and columns of a magic square produced new magic squares.
In 1691,
Simon de la Loubère described the Indian continuous method of constructing odd ordered magic squares in his book ''Du Royaume de Siam'', which he had learned while returning from a diplomatic mission to Siam, which was faster than Bachet's method. In an attempt to explain its working, de la Loubere used the primary numbers and root numbers, and rediscovered the method of adding two preliminary squares. This method was further investigated by Abbe Poignard in ''Traité des quarrés sublimes'' (1704), by
Philippe de La Hire in ''Mémoires de l'Académie des Sciences'' for the Royal Academy (1705), and by
Joseph Sauveur in ''Construction des quarrés magiques'' (1710). Concentric bordered squares were also studied by De la Hire in 1705, while Sauveur introduced magic cubes and lettered squares, which was taken up later by
Euler
Leonhard Euler ( ; ; ; 15 April 170718 September 1783) was a Swiss polymath who was active as a mathematician, physicist, astronomer, logician, geographer, and engineer. He founded the studies of graph theory and topology and made influential ...
in 1776, who is often credited for devising them. In 1750 d'Ons-le-Bray rediscovered the method of constructing doubly even and singly even squares using bordering technique; while in 1767
Benjamin Franklin
Benjamin Franklin (April 17, 1790) was an American polymath: a writer, scientist, inventor, statesman, diplomat, printer, publisher and Political philosophy, political philosopher.#britannica, Encyclopædia Britannica, Wood, 2021 Among the m ...
published a semi-magic square that had the properties of eponymous Franklin square. By this time the earlier mysticism attached to the magic squares had completely vanished, and the subject was treated as a part of recreational mathematics.
In the 19th century, Bernard Violle gave a comprehensive treatment of magic squares in his three volume ''Traité complet des carrés magiques'' (1837–1838), which also described magic cubes, parallelograms, parallelopipeds, and circles. Pandiagonal squares were extensively studied by Andrew Hollingworth Frost, who learned it while in the town of Nasik, India, (thus calling them Nasik squares) in a series of articles: ''On the knight's path'' (1877), ''On the General Properties of Nasik Squares'' (1878), ''On the General Properties of Nasik Cubes'' (1878), ''On the construction of Nasik Squares of any order'' (1896). He showed that it is impossible to have normal singly-even pandiagonal magic squares. Frederick A.P. Barnard constructed inlaid magic squares and other three dimensional magic figures like magic spheres and magic cylinders in ''Theory of magic squares and of magic cubes'' (1888).
In 1897, Emroy McClintock published ''On the most perfect form of magic squares'', coining the words ''pandiagonal square'' and ''most perfect square'', which had previously been referred to as perfect, or diabolic, or Nasik.
Some famous magic squares
Luo Shu magic square
Legends dating from as early as 650 BCE tell the story of the
Lo Shu (洛書) or "scroll of the river Lo".
According to the legend, there was at one time in
ancient China
The history of China spans several millennia across a wide geographical area. Each region now considered part of the Chinese world has experienced periods of unity, fracture, prosperity, and strife. Chinese civilization first emerged in the Y ...
a huge flood. While the
great king Yu was trying to channel the water out to sea, a
turtle
Turtles are reptiles of the order (biology), order Testudines, characterized by a special turtle shell, shell developed mainly from their ribs. Modern turtles are divided into two major groups, the Pleurodira (side necked turtles) and Crypt ...
emerged from it with a curious pattern on its shell: a 3×3 grid in which circular dots of numbers were arranged, such that the sum of the numbers in each row, column and diagonal was the same: 15. According to the legend, thereafter people were able to use this pattern in a certain way to control the river and protect themselves from floods. The
Lo Shu Square
The Luoshu (pinyin), Lo Shu (Wade-Giles), or Nine Halls Diagram is an Ancient China, ancient Chinese diagram and named for the Luo River (Henan), Luo River near Luoyang, Henan. The Luoshu appears in Chinese mythology, myths concerning the Chinese ...
, as the magic square on the turtle shell is called, is the unique normal magic square of order three in which 1 is at the bottom and 2 is in the upper right corner. Every normal magic square of order three is obtained from the Lo Shu by rotation or reflection.
Magic square in Parshavnath temple
There is a well-known 12th-century 4×4 normal magic square inscribed on the wall of the
Parshvanath temple in
Khajuraho, India.
This is known as the ''Chautisa Yantra'' (''Chautisa'', 34; ''
Yantra'', lit. "device"), since its magic sum is 34. It is one of the three 4×4
pandiagonal magic square
A pandiagonal magic square or panmagic square (also diabolic square, diabolical square or diabolical magic square) is a magic square with the additional property that the broken diagonals, i.e. the diagonals that wrap round at the edges of the squ ...
s and is also an instance of the
most-perfect magic square
A most-perfect magic square of order ''n'' is a magic square containing the numbers 1 to ''n''2 with two additional properties:
# Each 2 × 2 subsquare sums to 2''s'', where .
# All pairs of integers distant ''n''/2 along a (major) diagonal su ...
. The study of this square led to the appreciation of pandiagonal squares by European mathematicians in the late 19th century. Pandiagonal squares were referred to as Nasik squares or Jain squares in older English literature.
Albrecht Dürer's magic square
The order four normal magic square
Albrecht Dürer
Albrecht Dürer ( , ;; 21 May 1471 – 6 April 1528),Müller, Peter O. (1993) ''Substantiv-Derivation in Den Schriften Albrecht Dürers'', Walter de Gruyter. . sometimes spelled in English as Durer or Duerer, was a German painter, Old master prin ...
immortalized in his 1514 engraving ''
Melencolia I'', referred to above, is believed to be the first seen in European art. The square associated with Jupiter appears as a talisman used to drive away melancholy. It is very similar to
Yang Hui's square, which was created in China about 250 years before Dürer's time. As with every order 4 normal magic square, the magic sum is 34. But in the Durer square this sum is also found
in each of the quadrants, in the center four squares, and in the corner squares (of the 4×4 as well as the four contained 3×3 grids). This sum can also be found in the four outer numbers clockwise from the corners (3+8+14+9) and likewise the four counter-clockwise (the locations of four
queens
Queens is the largest by area of the Boroughs of New York City, five boroughs of New York City, coextensive with Queens County, in the U.S. state of New York (state), New York. Located near the western end of Long Island, it is bordered by the ...
in the two solutions of the
4 queens puzzle), the two sets of four symmetrical numbers (2+8+9+15 and 3+5+12+14), the sum of the middle two entries of the two outer columns and rows (5+9+8+12 and 3+2+15+14), and in four kite or cross shaped quartets (3+5+11+15, 2+10+8+14, 3+9+7+15, and 2+6+12+14). The two numbers in the middle of the bottom row give the date of the engraving: 1514. It has been speculated that the numbers 4,1 bordering the publication date correspond to Durer's initials D,A. But if that had been his intention, he could have inverted the order of columns 1 and 4 to achieve "A1514D" without compromising the square's properties.
Dürer's magic square can also be extended to a magic cube.
Sagrada Família magic square

The Passion façade of the
Sagrada Família
The Basílica i Temple Expiatori de la Sagrada Família, otherwise known as Sagrada Família, is a church under construction in the Eixample district of Barcelona, Catalonia, Spain. It is the largest unfinished Catholic church in the world. Desi ...
church in
Barcelona
Barcelona ( ; ; ) is a city on the northeastern coast of Spain. It is the capital and largest city of the autonomous community of Catalonia, as well as the second-most populous municipality of Spain. With a population of 1.6 million within c ...
, conceptualized by
Antoni Gaudí
Antoni Gaudí i Cornet ( , ; ; 25 June 1852 – 10 June 1926) was a Catalans, Catalan architect and designer from Spain, widely known as the greatest exponent of Catalan ''Modernisme''. Gaudí's works have a style, with most located in Barc ...
and designed by sculptor
Josep Subirachs, features a trivial order 4 magic square: The magic constant of the square is 33, the age of
Jesus
Jesus (AD 30 or 33), also referred to as Jesus Christ, Jesus of Nazareth, and many Names and titles of Jesus in the New Testament, other names and titles, was a 1st-century Jewish preacher and religious leader. He is the Jesus in Chris ...
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.
Trivial squares such as this one are not generally mathematically interesting and only have historical significance. Lee Sallows has pointed out that, due to Subirachs's ignorance of magic square theory, the renowned sculptor made a needless blunder, and supports this assertion by giving several examples of non-trivial 44 magic squares showing the desired magic constant of 33.
Similarly to Dürer's magic square, the Sagrada Familia's magic square can also be extended to a magic cube.
Parker square
The Parker square, named after recreational mathematician and maths YouTuber
Matt Parker
Matthew Thomas Parker (born 22 December 1980) is an Australian recreational mathematics, recreational mathematician, author, comedian, YouTube personality and Science communication, science communicator based in the United Kingdom. His book ''H ...
, is an attempt to create a 33 magic square of
squares
In geometry, a square is a regular polygon, regular quadrilateral. It has four straight sides of equal length and four equal angles. Squares are special cases of rectangles, which have four equal angles, and of rhombuses, which have four equal si ...
— a prized unsolved problem since
Euler
Leonhard Euler ( ; ; ; 15 April 170718 September 1783) was a Swiss polymath who was active as a mathematician, physicist, astronomer, logician, geographer, and engineer. He founded the studies of graph theory and topology and made influential ...
. Discovered in 2016, the Parker square is a trivial semimagic square, since it uses some numbers more than once, and the diagonal sums to , not as for all the other rows and columns, and the other diagonal. A true 33 magic square of square numbers has to date not been discovered (despite computer searches). In a ''
Numberphile
''Numberphile'' is an Educational entertainment, educational YouTube channel featuring videos that explore topics from a variety of fields of mathematics. In the early days of the channel, each video focused on a specific number, but the channe ...
'' video from June 2023, Mathematician Tony Várilly-Alvarado used mathematics to speculate that the existence of such a square is "probably impossible". In February 2025, Parker upped his years-old bounty of US$1,000 to $10,000 to find a fully magic 33 square using square numbers.
Gardner square
The Gardner square, named after recreational mathematician
Martin Gardner
Martin Gardner (October 21, 1914May 22, 2010) was an American popular mathematics and popular science writer with interests also encompassing magic, scientific skepticism, micromagic, philosophy, religion, and literatureespecially the writin ...
, similar to the Parker square,
is given as a problem to determine a, b, c and d.
This solution for a = 74, b = 113, c = 94 and d = 97 gives a semimagic square; the diagonal sums to , not as for all the other rows and columns, and the other diagonal.
Properties of magic squares
Magic constant
The constant that is the sum of any row, or column, or diagonal is called the
magic constant or magic sum, ''M.'' Every normal magic square has a constant dependent on the order , calculated by the formula
. This can be demonstrated by noting that the sum of
is
. Since the sum of each row is
, the sum of
rows is
, which when divided by the order yields the magic constant as
. For normal magic squares of orders ''n'' = 3, 4, 5, 6, 7, and 8, the magic constants are, respectively: 15, 34, 65, 111, 175, and 260 (sequence
A006003 in the
OEIS).
Magic square of order 1 is trivial
The 1×1 magic square, with only one cell containing the number 1, is called ''
trivial'', because it is typically not under consideration when discussing magic squares; but it is indeed a magic square by definition, if a single cell is regarded as a square of order one.
Magic square of order 2 cannot be constructed
Normal magic squares of all sizes can be constructed except 2×2 (that is, where order ''n'' = 2).
Center of mass
If the numbers in the magic square are seen as masses located in various cells, then the
center of mass
In physics, the center of mass of a distribution of mass in space (sometimes referred to as the barycenter or balance point) is the unique point at any given time where the weight function, weighted relative position (vector), position of the d ...
of a magic square coincides with its geometric center.
Moment of inertia
The ''moment of inertia'' of a magic square has been defined as the sum over all cells of the number in the cell times the squared distance from the center of the cell to the center of the square; here the unit of measurement is the width of one cell.
[ (Thus for example a corner cell of a 3×3 square has a distance of a non-corner edge cell has a distance of 1, and the center cell has a distance of 0.) Then all magic squares of a given order have the same moment of inertia as each other. For the order-3 case the moment of inertia is always 60, while for the order-4 case the moment of inertia is always 340. In general, for the ''n''×''n'' case the moment of inertia is ][
]
Birkhoff–von Neumann decomposition
Dividing each number of the magic square by the magic constant will yield a doubly stochastic matrix
In mathematics, especially in probability and combinatorics, a doubly stochastic matrix
(also called bistochastic matrix) is a square matrix X=(x_) of nonnegative real numbers, each of whose rows and columns sums to 1, i.e.,
:\sum_i x_=\sum_j x_ ...
, whose row sums and column sums equal to unity. However, unlike the doubly stochastic matrix, the diagonal sums of such matrices will also equal to unity. Thus, such matrices constitute a subset of doubly stochastic matrix. The Birkhoff–von Neumann theorem states that for any doubly stochastic matrix , there exists real numbers , where and permutation matrices
In mathematics, particularly in Matrix (mathematics), matrix theory, a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column with all other entries 0. An permutation matrix can represent a permu ...
such that
:
This representation may not be unique in general. By Marcus-Ree theorem, however, there need not be more than terms in any decomposition. Clearly, this decomposition carries over to magic squares as well, since a magic square can be recovered from a doubly stochastic matrix by multiplying it by the magic constant.
Classification of magic squares
While the classification of magic squares can be done in many ways, some useful categories are given below. An ''n''×''n'' square array of integers 1, 2, ..., ''n''2 is called:
* ''Semi-magic square'' when its rows and columns sum to give the magic constant.
* ''Simple magic square'' when its rows, columns, and two diagonals sum to give magic constant and no more. They are also known as ''ordinary magic squares'' or ''normal magic squares''.
* ''Self-complementary magic square'' when it is a magic square which when complemented (i.e. each number subtracted from ''n''2 + 1) will give a rotated or reflected version of the original magic square.
* '' Associative magic square'' when it is a magic square with a further property that every number added to the number equidistant, in a straight line, from the center gives ''n''2 + 1. They are also called ''symmetric magic squares''. Associative magic squares do not exist for squares of singly even order. All associative magic square are self-complementary magic squares as well.
* ''Pandiagonal magic square
A pandiagonal magic square or panmagic square (also diabolic square, diabolical square or diabolical magic square) is a magic square with the additional property that the broken diagonals, i.e. the diagonals that wrap round at the edges of the squ ...
'' when it is a magic square with a further property that the broken diagonals sum to the magic constant. They are also called ''panmagic squares'', ''perfect squares'', ''diabolic squares'', ''Jain squares'', or ''Nasik squares''. Panmagic squares do not exist for singly even orders. However, singly even non-normal squares can be panmagic.
* ''Ultra magic square'' when it is both associative and pandiagonal magic square. Ultra magic square exist only for orders ''n'' ≥ 5.
* ''Bordered magic square'' when it is a magic square and it remains magic when the rows and columns on the outer edge are removed. They are also called ''concentric bordered magic squares'' if removing a border of a square successively gives another smaller bordered magic square. Bordered magic square do not exist for order 4.
* ''Composite magic square'' when it is a magic square that is created by "multiplying" (in some sense) smaller magic squares, such that the order of the composite magic square is a multiple of the order of the smaller squares. Such squares can usually be partitioned into smaller non-overlapping magic sub-squares.
* ''Inlaid magic square'' when it is a magic square inside which a magic sub-square is embedded, regardless of construction technique. The embedded magic sub-squares are themselves referred to as ''inlays''.
* ''Most-perfect magic square
A most-perfect magic square of order ''n'' is a magic square containing the numbers 1 to ''n''2 with two additional properties:
# Each 2 × 2 subsquare sums to 2''s'', where .
# All pairs of integers distant ''n''/2 along a (major) diagonal su ...
'' when it is a pandiagonal magic square with two further properties (i) each 2×2 subsquare add to 1/''k'' of the magic constant where ''n'' = 4''k'', and (ii) all pairs of integers distant ''n''/2 along any diagonal (major or broken) are complementary (i.e. they sum to ''n''2 + 1). The first property is referred to as ''compactness'', while the second property is referred to as ''completeness''. Most-perfect magic squares exist only for squares of doubly even order. All the pandiagonal squares of order 4 are also most perfect.
* ''Franklin magic square'' when it is a doubly even magic square with three further properties (i) every bent diagonal adds to the magic constant, (ii) every half row and half column starting at an outside edge adds to half the magic constant, and (iii) the square is ''compact''.
* '' Multimagic square'' when it is a magic square that remains magic even if all its numbers are replaced by their ''k''-th power for 1 ≤ ''k'' ≤ ''P''. They are also known as ''P-multimagic square'' or ''satanic squares''. They are also referred to as ''bimagic squares'', ''trimagic squares'', ''tetramagic squares'', and ''pentamagic squares'' when the value of ''P'' is 2, 3, 4, and 5 respectively.
Enumeration of magic squares
;Low-order squares
There is only one (trivial) magic square of order 1 and no magic square of order 2. As mentioned above, the set of normal squares of order three constitutes a single equivalence class
In mathematics, when the elements of some set S have a notion of equivalence (formalized as an equivalence relation), then one may naturally split the set S into equivalence classes. These equivalence classes are constructed so that elements ...
-all equivalent to the Lo Shu square. Thus there is basically just one normal magic square of order 3.
The number of different ''n'' × ''n'' magic squares for ''n'' from 1 to 6, not counting rotations and reflections is:
: 1, 0, 1, 880, 275305224, 17753889197660635632.
The number for ''n'' = 6 had previously been estimated to be ["Number of Magic Squares From Parallel Tempering Monte Carlo]
arxiv.org, April 9, 1998. Retrieved November 2, 2013.
; Magic tori
Cross-referenced to the above sequence, a new classification enumerates the magic tori that display these magic squares. The number of magic tori of order ''n'' from 1 to 5, is:
: 1, 0, 1, 255, 251449712 .
; Higher-order squares and tori
The number of distinct normal magic squares rapidly increases for higher orders.
The 880 magic squares of order 4 are displayed on 255 magic tori of order 4 and the 275,305,224 squares of order 5 are displayed on 251,449,712 magic tori of order 5. The numbers of magic tori and distinct normal squares are not yet known for orders beyond 5 and 6, respectively.[Anything but square: from magic squares to Sudoku]
by Hardeep Aiden, Plus Magazine
''Plus Magazine'' is an online popular mathematics magazine run under the Millennium Mathematics Project at the University of Cambridge.
''Plus'' contains:
* feature articles on all aspects of mathematics;
* reviews of popular maths books an ...
, March 1, 2006
Algorithms tend to only generate magic squares of a certain type or classification, making counting all possible magic squares quite difficult. Since traditional counting methods have proven unsuccessful, statistical analysis using the Monte Carlo method
Monte Carlo methods, or Monte Carlo experiments, are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. The underlying concept is to use randomness to solve problems that might be ...
has been applied. The basic principle applied to magic squares is to randomly generate ''n'' × ''n'' matrices of elements 1 to ''n''2 and check if the result is a magic square. The probability that a randomly generated matrix of numbers is a magic square is then used to approximate the number of magic squares.
More intricate versions of the Monte Carlo method, such as the exchange Monte Carlo, and Monte Carlo backtracking have produced even more accurate estimations. Using these methods it has been shown that the probability of magic squares decreases rapidly as n increases. Using fitting functions give the curves seen to the right.
Transformations that preserve the magic property
For any magic square
* The sum of any two magic squares of the same order by matrix addition
In mathematics, matrix addition is the operation of adding two matrices by adding the corresponding entries together.
For a vector, \vec\!, adding two matrices would have the geometric effect of applying each matrix transformation separately ...
is a magic square.
* A magic square remains magic when all of its numbers undergo the same non-constant linear function
In mathematics, the term linear function refers to two distinct but related notions:
* In calculus and related areas, a linear function is a function whose graph is a straight line, that is, a polynomial function of degree zero or one. For di ...
(i.e., a function of the form with ''m'' nonzero). For example, a magic square remains magic when its numbers are multiplied by any nonzero constant. Moreover, a magic square remains magic when a constant is added or subtracted to its numbers, or if its numbers are subtracted from a constant. In particular, if every element in a normal magic square of order is subtracted from , the complement of the original square is obtained. In the example below, each element of the magic square on the left is subtracted from 17 to obtain the complement magic square on the right.
* A magic square remains magic when transformed by any element of , the symmetry group of a square (see ). Every combination of one or more rotations of 90 degrees, reflections, or both produce eight trivially distinct squares which are generally considered equivalent. The eight such squares are said to make up a single equivalence class
In mathematics, when the elements of some set S have a notion of equivalence (formalized as an equivalence relation), then one may naturally split the set S into equivalence classes. These equivalence classes are constructed so that elements ...
. The eight equivalent magic squares for the 3×3 magic square are shown below:
* A magic square of order remains magic when both its rows and columns are symmetrically permuted by such that for . Every permutation of the rows or columns preserves all row and column sums, but generally not the two diagonal sums. If the same permutation is applied to both the rows and columns, then diagonal element in row and column is mapped to row and column which is on the same diagonal; therefore, applying the same permutation to rows and columns preserves the main (upper left to lower right) diagonal sum. If the permutation is symmetric as described, then the diagonal element in row and column is mapped to row and column which is on the same diagonal; therefore, applying the same symmetric permutation to both rows and columns preserves both diagonal sums. For even , there are such symmetric permutations, and for odd. In the example below, the original magic square on the left has its rows and columns symmetrically permuted by resulting in the magic square on the right.
* A magic square of order remains magic when rows and are exchanged and columns and are exchanged because this is a symmetric permutation of the form described above. In the example below, the square on the right is obtained by interchanging the 1st and 4th rows and columns of the original square on the left.
* A magic square of order remains magic when rows and are exchanged, rows and are exchanged, columns and are exchanged, and columns and are exchanged where