The world's oldest dated four-by-four magic square was a perfume recipe
Around 550 CE the Indian scholar Varahamihira drew a four-by-four grid for blending perfumes. Each cell named an ingredient and its proportion, and any four picked along a row, column or diagonal always made a mixture totalling 18. It is the oldest dateable magic square of its size anywhere.
A magic square is a grid of numbers in which every row, every column and both main diagonals add to the same total, the magic constant. Squares using each of the whole numbers from one upward exactly once are called normal; those with repeats, like the famous one on the Sagrada Família, count as trivial, and those whose diagonals fail are semimagic. Mathematicians sort them by size into odd, doubly even and singly even, because each group needs its own construction trick, such as bordering a smaller square or building composites. Beyond size five, nobody has yet counted how many exist.
China had the three-by-three square by 190 BCE, when it was used mainly for divination and called the Nine Halls; only in the twelfth century was it linked to the legendary Luoshu chart. Yang Hui's treatise of 1275 showed squares up to order nine plus magic circles, though historians judge Chinese methods less advanced than later Indian and Middle Eastern ones. An encyclopedia compiled in Baghdad around 983 already contained squares of order three to nine, and by the end of the twelfth century general construction methods were established there, sometimes paired with magic letters for occult use.
India contributed more than perfume. The alchemist Nagarjuna described a four-by-four square summing to 100, and in 1356 Narayana listed every four-by-four pandiagonal square, whose broken diagonals also add up. Japanese mathematicians took up the puzzle in the seventeenth century; Seki Takakazu gave a general treatment, and Yueki Ando displayed squares up to order 30.
Europe learned of them from Arabic texts during the Renaissance, largely as occult objects, and had to rediscover the theory. One sits in Albrecht Dürer's engraving Melencolia. Strikingly, Greek, Babylonian and Egyptian mathematicians never found them at all.
Source: Magic square