When Lee Sallows was in his 20s he moved from London to the Netherlands and dropped a lot of LSD. During one acid trip he started doodling with magic squares, a type of mathematical pursuit he had recently read about in a scientific magazine.

A magic square is a grid of numbers for which every line, column and diagonal adds up to the same number. For example:

4 9 2

3 5 7

8 1 6

In this case, the rows, columns and diagonals all equal 15.

The magic square is a simple concept and one that has been around for thousands of years. Mathematicians, artists and mystics have long been fascinated by the mesmerising patterns that they produce, and perhaps it is not surprising that Sallows, under the influence of hallucinogenic drugs, was taken under their spell.

After the acid wore off, however, Sallows's interest in magic squares did not wane. It became an obsession. In fact, he became so fixated on them that after a couple of decades of contemplation he discovered a whole new category of square, which is opening a fascinating new chapter for one of the oldest genres in maths.

Sallows did something very simple, although it had never been done before. He filled his squares with geometrical shapes rather than numbers. Instead of every row, column and diagonal having to add up to the same number, the shapes in each row, column and diagonal had to fit together to create the same master-shape.

He called his invention the "geomagic square". They are an entirely fresh way to appreciate the subtleties of magic squares, and provide beautiful geometric patterns, too.

Left, a geomagic 3x3 square where each element is a decomino – a polyomino made up of 10 square units. The decominoes in each row, column and diagonal can be fitted together to form a 5x6 rectangle. (They can be assembled in two different ways, which are drawn on either side of each row, column and diagonal.) This is one of only two geomagic squares possible when the pieces are all decominoes - making this type of geomagic square much rarer than when all the pentominoes from one to nine are used. Right, a geomagic 3x3 square where each element is a polyomino, ranging in size from one to nine. The squares around the periphery show how the polyominoes from the corresponding rows, columns and diagonals can be pieced together to form the same shape, in this case a 4x4 square with one internal cell removed. Sallows found 4,370 squares like this, consisting of the polyominoes from one to nine, and making the same target shape - many more than he expected.

Peter Cameron, professor of mathematics at Queen Mary, University of London, calls geomagic squares "a wonderful new piece of recreational maths, which will delight non-mathematicians and give mathematicians food for thought". Despite the inherent whimsy of the field, he said: "I have no doubt that there is serious maths to be done here, too."

Perhaps no other area of non-practical mathematics has been so popular for so long as magic squares. Their story begins 4,000 years ago in China, where, according to legend, a turtle crept out of the Yellow River. The reptile is said to have had dots on its underside positioned in such a way as to make the 3x3 square described above.

The Chinese called this square the lo shu, and gave it spiritual importance, believing that it encapsulated the harmonies of the universe. Feng shui, the Chinese system of arranging objects, such as furniture in homes, is in part based on the lo shu.

But veneration of magic squares was not confined to the Chinese. In India amulets with magic squares were worn as protective charms, in Turkey virgins embroidered magic squares on the shirts of warriors and in western Europe Renaissance astrologers equated them with planets.

In 1514, the German artist and mathematician Albrecht Dürer produced his most famous work, Melencolia I, a woodcut portraying a troubled-looking angel surrounded by scientific objects, which included the following 4x4 square:

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

This square is particularly amazing. Not only do the rows, lines and diagonals add up to 34, but the four corners, the four digits in the central square, and the four digits in the top left, top right, bottom left and bottom right quarters do too. There are many other combinations of four numbers in the square that add up to 34, and it is fun looking for them. Dürer even included the year he made the engraving – 1514 – on the bottom line.

Some great mathematicians studied magic squares – such as Leonhard Euler in the 18th century, and Édouard Lucas and Arthur Cayley in the 19th – but the field has generally been the domain of passionate laypeople. The most notable aficionado was United States founding father Benjamin Franklin, who liked to spend his spare time constructing particularly innovative variations. In one evening in his 40s he composed a 16x16 square that he claimed was "the most magically magical of any magic square ever made by any magician".

Sallows, aged 66, is very much an enthusiastic amateur. He left school at 17 with no qualifications and his mathematics is entirely self-taught. He was an electronics engineer in the non-academic staff at the University of Nijmegen until he retired two years ago.

While it is certainly remarkable that a non-mathematician has given this established field a new lease of life, it is perhaps only to be expected, since most academic mathematicians would now consider magic squares as too frivolous to occupy their time.

The conventional magic square has n rows and n columns, and must include every number from 1 to n². So, as above, the 3x3 has every number from one to nine and the 4x4 every number from one to 16.

Sallows says he was instantly "turned on by the symmetries" of magic squares, and once he had got the bug he began to invent new rules and modifications. He is celebrated for inventing the "alphamagic square", which is doubly magic:

five twenty-two eighteen

twenty-eight fifteen two

twelve eight twenty-five

The rows, columns and diagonals add up to 45 when considering the meaning of the words. But when considering the number of letters in each word – so five is 4 and twenty-two is 9 – this also generates a magic square, whose rows, columns and diagonals add up to 21. Another fantastic property of this square is that the word lengths consist of the consecutive numbers from 3 to 11.

Sallows gained a certain amount of fame in the recreational maths world for his alphamagic square, but dismisses it as "zany, a bit silly".

He was more excited by looking at the algebra behind magic squares. Édouard Lucas had discovered this formula, which yields a magic square when you substitute a, b and c for numbers:

a+b a-b-c a+c

a-b+c a a+b-c

a-c a+b+c a-b

When you let a = 5, b = –1 and c = –3, you get the lo shu.

Sallows was playing around with the Lucas formula: "And then it came to me – why don't I represent the variables by shapes? A 'plus' could be appending, and a 'minus' excising. From that everything else followed. It is absolutely incredible that nobody else had thought of it before. I knew at once I had landed on a really important idea. My mind was crowded with possibilities."

As we saw above, the rows, columns and diagonals of a magic square add up to the same number. If each number in the square is represented by a line of that length, then it follows that these line segments can be joined head to tail to form a larger line – and this line will have the same length whichever row, column or diagonal you choose.

Similarly, if each number n is replaced by a shape that has area n, it follows that the shapes on each row, column and diagonal when put together will have the same combined area.

Yet Sallows wanted the extra condition that the shapes fit together so that each row, column and diagonal made the exact same target shape.

"It was a very complicated business," he said. Using a computer it took a long time to find shapes that worked and when he did: "I really fell of my chair."

Sallows had been under the impression that geomagic squares would be few and far between. Yet he found thousands of them. "It was the complete opposite of what I expected. I was looking for something incredibly rare but discovered it wasn't rare at all."

The lo shu is the only 3x3 magic square that it is possible to construct when the numbers from one to nine are all used. (Excluding squares made from rotating it and reflecting it, which are regarded as mathematically equivalent.)

But when Sallows filled his 3x3 geomagic square with nine polyominoes that have areas from 1 to 9 – that is, shapes made from one unit square, two unit squares, three, and so on until nine unit squares – he found that there are 1,411 geomagic squares when the target shape is a 3x5 rectangle. He was able to find 4,370 geomagic squares where the target shape is a 4x4 square missing one central piece, 27,110 when the target is a 4x4 square missing one corner piece and 16,465 when the target is missing a non-corner edge piece.

Sallows claims his discoveries have cast magic squares in a completely new light. "Nobody ever understood what a magic square is," he says. "We have always assumed they are numerical objects. From this perspective they are all geometrical objects, and only a small subset are numerical objects."

Sallows has gone on to find dozens of new types of geomagic square, involving combinations of all sorts of shapes. He uploaded a gallery of his discoveries on to the web on Christmas Day last year, and since then more than 34,000 people from 129 countries have clicked on his site – making it a viral hit in the world of recreational maths.

Might Sallows's insight have any practical uses? "I don't believe that any of this stuff is of the slightest significance," he replies. "It is delightful and charming and appeals to everyone, but has no application whatsoever."

Peter Cameron, at the University of London, is more circumspect, since applications are hard to predict: "Euler discovered Latin squares when he was giving a new construction for magic squares; these now have wide application in many areas including experimental design. Maybe there are 'geo-Latin squares' that would have some application."

Whether or not uses are found, however, Sallows has certainly proved one thing: that the age-old fascination with magic squares is not over yet.

Alex Bellos is the author of Alex's Adventures in Numberland