More formally, a magic square can be defined as an *n*-by-*n* matrix such that the sum of any row, column or main diagonal yields the same result (the square's magic constant, denoted *M*_{2}(*n*)); if these numbers are 1, 2,..., *n*², then

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.

The Lo Shu Square, as the magic square on the turtle shell is called, is an important part of Feng Shui, the ancient Chinese art of geomancy. Traditional Chinese cities and temples were laid out in a square broken into nine sections; the odd numbers in the Lo Shu Square are male or yang, while the even numbers are female or yin. The numbers 1, the beginning of all things, and 9, representing completion, are considered most auspicious, while the number 5 at the centre is the most powerful. The Lo Shu square, in the form of a trigram, gives the basis for determining the orientation of buildings, and is also a diagrammatic representation of the seasons showing the ratio of yin and yang in the annual cycle.

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.

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 pandiagonal magic square where, in addition to the rows, columsn and main diagonals, the broken diagonals also have the same sum.

Magic squares 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, prevention against diseases etc.. The Kubera-Kolam is a floor painting used in India which is in the form of a magic square of order three. It begins with the number twenty and ends with the number twenty-eight.

The 4x4 magic square in Albrecht Dürer's engraving *Melancholia I* is believed to be the first seen in European art. The sum 34 can be found in the rows, columns, diagonals, any 2x2 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, and the sum of the middle two entries of the two outer columns and rows (eg 5 + 9 + 8 + 12), as well as several kite-shaped quartets, eg 3 + 5 + 11 + 15; the two numbers in the middle of the bottom row give the date of the engraving: 1514.

It has been known since 1693 that there exist 880 basic (excluding those obtained by rotation and reflection) 4x4 magic squares and 275305224 basic 5x5 magic squares. The number of basic magic squares of any higher degreee is not yet known but it was estimated by Klaus Pinn and C. Wieczerkowski (1998) using Monte Carlo simulation and methods from statistical mechanics to be (1.7745 ± 0.0016) × 10^{19} in the 6x6 case squares and (3.7982 ± 0.0004) × 10^{34} in the 7x7 case.

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

Order 3 | Order 5 | Order 9 |

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.

Order 8

- Satanic square
- Diabolic square
- Prime reciprocal magic square
- Bimagic square
- Trimagic square
- Multimagic square
- Magic Star
- Magic cube
- Magic tesseract

- 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)