There Are Magic Hexagons of Every Order | gukov.dev
What is so special about the number 19?
The question came up last month in a conversation among YSDA alumni, when the school turned 19. Someone pointed out that 19 is a twin prime. Someone else replied that 19 is the number of cells in the only non-trivial normal magic hexagon.
Wait, what is a “magic hexagon”? Let us start there.
A note on AI-assisted mathematics
Recently, we have heard a lot about AI miraculously proving and disproving<br>long-standing conjectures, often without much explanation of how it was done.
This story offers a look inside the process of making such a mathematical<br>discovery.
Magic Squares and Magic Hexagons
You probably know about magic squares. A magic square is a square grid of numbers in which every row, every column, and both main diagonals add up to the same total, known as the magic constant. We also usually require the numbers to be consecutive - typically from $1$ to $n^2$ - and call it a normal magic square. Otherwise, we could simply put the same number into every cell, which would be a very boring way to fill a square.
All illustrations on this page are interactive. Click on them!
Magic squares have been known for millennia and are now very well understood. We have algorithms for constructing normal magic squares of every order $n>2$.
A magic hexagon applies the same idea to a hexagonal grid. Its cells form straight lines in three directions, and every such line must have the same sum. As with squares, a magic hexagon is called normal if it contains the consecutive numbers from $1$ to $3n^2-3n+1$, the total number of cells in a hexagon of order $n$.
Above you can see the only non-trivial normal magic hexagon in existence - apart from its own rotations and reflections. The proof is straightforward. In each of the three directions, the cells are partitioned into $2n-1$ lines. Therefore, the sum of all the numbers must be divisible by $2n-1$. For every order $n>3$, the sum of the numbers from $1$ to $3n^2-3n+1$ fails this divisibility test.
Well, ending the story here would be no fun. To make things more interesting, let’s look at the so-called abnormal magic hexagons. Here we relax one constraint: the numbers on the grid must still be consecutive, but they no longer have to start at $1$.
This small relaxation suddenly allows new solutions to appear.
Finding them, however, is not easy. Unlike with magic squares, there was no formulaic construction or deterministic algorithm. The only known approach was to wander through a brutally large search space of possible arrangements. According to Wikipedia, as of July 2026, the largest known solution was a hexagon of order $n=9$, found by Klaus Meffert in 2024.
So… what makes these solutions so hard to find? And how about we try?
Chapter 1: Making Observations (With Human Brain)
There is a clear tension between two independent constraints:
The numbers must be consecutive;
All line sums must be equal, even though the lines have different lengths.
The prior solutions I found suggested that people had already tried several search algorithms and likely optimized them well.<br>That made me think that, if I wanted to advance the field, I should focus not on making the search faster, but on making the search space smaller.
Observation: Antisymmetric hexagons are much simpler
First, let’s restrict the numbers on the grid to the symmetric interval $-K,\ldots,K$ for some $K$. If all line sums are equal, this is equivalent to requiring that every line sum be zero.
Second, put $0$ in the center and require that cells opposite each other under a 180-degree rotation contain opposite values. If one cell contains $x$, its antipodal cell contains $-x$.
Notice how many constraints disappear. Every line through the center sums to zero automatically because its values cancel in opposite pairs. Every other line has an antipodal line with the sum of antipodal opposite numbers. If one of them sums to zero, so does the other.
Of course, simplifying the constraints introduces a risk: perhaps no solutions satisfy the extra symmetry at all. At this point, antisymmetry was simply a plausible place to search, following the drunkard’s principle.
But once I started thinking about zero-sum hexagons, another structure appeared.
Observation: Every zero-sum hexagon is build from the same 6-point ring
Quick note
This observation is interesting but not essential for what comes next. I you find it hard to follow, feel free to skip this part.
Consider any hexagonal grid, zero-sum or not. Take the six cells surrounding any interior point and add the alternating pattern \([-1,+1,-1,+1,-1,+1].\) Leave the central cell unchanged.
Every straight line that intersects this ring receives either no contribution or two opposite contributions, $+1$ and $-1$. Its sum therefore remains unchanged. We can add any multiple of this pattern without changing a single line sum.
These local alternating rings form...