Exploring the Hilbert Curve
The Hilbert Curve: How Can a Single Line Fill an Entire Space?
Imagine holding a pen where the tip can only move along a single continuous line—you cannot lift the pen or draw a second line. Now, here is the task: use this single continuous line to traverse the entire area of a square.
It sounds impossible, doesn't it? After all, a line is one-dimensional, while a square is two-dimensional. How could a one-dimensional line with no thickness possibly cover a two-dimensional surface?
But the mathematician Hilbert showed us that if we allow the line to bend and refine itself repeatedly, something truly remarkable happens. This is the Hilbert curve.
Starting with a Very Simple Pattern
The first iteration of the Hilbert curve is actually quite simple; you can visualize it as a U shape.
There is no complex mathematics or intricate detail—just a single curved line.
This is the Hilbert curve in its initial form.
What happens at the next stage?
Now, the question arises: what should we do if we want to make this curve more complex?
A natural idea is to make several copies of the shape we just created and then connect them.
So, we scale down the U-shaped curve to create four smaller U-shapes and place them into the four quadrants of the square.
However, it isn't quite that simple; if all four U-shapes maintained their original orientation, their endpoints wouldn't connect naturally. Therefore, we need to rotate—and in some cases, flip—some of the U-shapes. This allows the four small curves to be arranged with the proper orientation so they can be connected. The process is: scale down → arrange → rotate/flip → connect.
The result is a continuous curve that is far more complex than the original.
A common question arises here: why can't we simply place the four U-shapes together?
Because what we aim to create is not four disconnected curves, but a single continuous curve; thus, the start and end points of each small curve must be positioned correctly. Rotating or flipping changes the orientation of these small curves, enabling them to connect to one another.
Therefore, rotation isn't just about making the pattern 'look better'; it is a crucial step in the construction process that ensures the different sections connect in the right direction. At the same time, placing the four small curves into separate regions allows each to occupy a specific part of the square, preventing them from all being crowded together.
But the truly important part comes next
We now have a curve that is far more complex than the one we started with. So, what happens at the next iteration?
This is the core of the Hilbert curve: the entire figure we just obtained becomes the foundation for constructing the figure at the next level. In other words, we don't start over by drawing the initial 'U' shape every time; instead, the entire curve from the previous level becomes the basic shape used to construct the next level.
For the next level, we take the figure from the previous level (which is no longer just a 'U'), scale it down, create four copies, place them into different sections of the square, rotate or flip them as needed, and connect them together. This results in an even more complex curve.
Once the next level is complete, we can keep going.
We use the curve we just obtained as the foundation for the next level, then: scale down → arrange → rotate/flip → connect, yielding a curve of an even higher order.
Then we continue, and continue, and continue...
Therefore, the essence of the Hilbert curve isn't any single, incredibly complex shape. Rather, it is a set of very simple rules: scale down the curve from the previous level into several parts, rearrange them, adjust their orientation, connect them, and repeat the process. Simple rules, through continuous repetition, ultimately give rise to an incredibly complex structure.
What is "order"?
We can call the different structural levels of the Hilbert curve: order.
First order, only the simplest U shape.
The second order consists of four first orders that have been reduced and adjusted in direction, and the curve begins to become complicated.
Third order, the second order is divided into smaller parts, and the curve begins to have an obvious grid structure.
The fourth level, there are more and more bends and the lines are getting denser and denser.
Fifth level, the entire square has been covered by very dense curves.
So, the higher the order, the more levels of recursive construction we have performed. The "recursion" here simply means using the results obtained before and continuing to construct new results.
As the order continues to increase, the curve becomes denser and denser. It no longer looks like an ordinary "line". It becomes more and more like a dense two-dimensional map.
Keep increasing. The gaps between the lines become smaller and smaller. If you increase more, the gaps will become smaller. If you increase more, the curves will become denser.
If we continue this process, we will eventually get an extremely counter-intuitive result: This continuous curve can cover the entire square. This is the most famous feature of the Hilbert curve.
Can a line really turn into a surface?
We need to pause here for a brief explanation. When we say, 'The Hilbert curve fills the entire square,' we do not mean that you simply draw a thick line and color in the square.
What it actually means is: As the order approaches infinity, the Hilbert curve passes through every single point within the square.
In other words, for any location within the square, there is a corresponding point on the curve.
Therefore, the Hilbert curve is classified as a space-filling curve.
What does "space-filling" mean?
You can think of it as a very diligent robot.
The robot follows a single path; it cannot fly, jump, or teleport—it can only move along a continuous route.
If the path is relatively coarse, it only passes through certain areas of the square. However, as the curve becomes increasingly refined, the path grows denser. It enters smaller and smaller regions, loops around, returns, enters the next region, returns again...
The path becomes finer and covers more and more space. Ultimately, in the limit, every single point within the square is visited by this path.
This is what is known as 'space-filling'.
Now we can return to a deeper question: Why does the Hilbert curve eventually cover the entire square instead of leaving behind unreachable spots? The key lies in the fact that the construction of the curve continuously subdivides the space.
At lower orders, the square is divided into relatively large regions that the curve enters. At higher orders, these regions are further split into smaller ones, which the curve continues to enter. At the next order, these regions are subdivided again; thus, the space is partitioned ever more finely while the curve becomes increasingly dense. Consequently, as the order increases, the gaps between segments of the curve shrink. In the limit of infinite refinement, these gaps approach zero. Therefore, no fixed small region can remain forever outside the reach of the curve.
You can visualize this as a sweeping process that becomes increasingly fine-grained—one of the most intuitive ways to understand the Hilbert curve.
Imagine tracing the entire square with a pen.
Order 1: You draw a relatively rough path, leaving behind large empty spaces.
Order 2: The path becomes denser, and the empty spaces diminish.
Order 3: The path grows even denser, leaving fewer empty spaces.
Order 4: The path is already extremely dense.
……
As the process continues, the empty space shrinks. Ultimately, in the limit, the empty space vanishes—this is space-filling.
However, this differs from simply 'coloring in' a shape; there is a fascinating distinction here.
If you were to blacken the entire square with a brush, it would certainly be easy to fill it in by moving back and forth.
But the Hilbert curve imposes a much stricter requirement: you must draw a single continuous line—no lifting the pen, no jumping, and no drawing a second, separate line.
Even with this constraint, it can still cover the entire area in the limit. So, the truly magical part isn't just 'filling the square,' but the fact that you can traverse the entire two-dimensional space using only a single continuous curve.
What Makes the Hilbert Curve So Special?
By now, we have seen the most surprising aspect of the Hilbert curve.
It begins as a simple curve and grows increasingly complex step-by-step through a repeating process of scaling down → arranging → rotating/flipping → connecting.
Ultimately, it yields more than just a complex pattern; it succeeds in covering the entire 2D square with a single continuous curve—a feature that sets it apart from many ordinary fractals.
A Crucial Characteristic: Self-Similarity
Now that we understand how the Hilbert curve is constructed order by order, let’s revisit a fascinating phenomenon.
Remember how we mentioned that the entire curve from a previous order serves as the foundation for the next? This means that within a higher-order Hilbert curve, you will find smaller regions that look remarkably similar to lower-order Hilbert curves. For instance, a third-order curve can be viewed as a collection of second-order curves that have been scaled down, rotated, or flipped; likewise, a second-order curve is composed of multiple first-order curves.
This phenomenon—where the whole contains structural parts that resemble the whole itself—is known as self-similarity, and it is a defining characteristic of fractal structures.
How can a “one-dimensional” object cover a “two-dimensional” one?
This is one of the most thought-provoking aspects of the Hilbert curve.
We generally think of a line as one-dimensional and a square as two-dimensional; intuitively, therefore, it seems impossible for a line to cover a square.
For an ordinary line, this assessment is certainly correct.
However, the Hilbert curve is a unique mathematical construct. It is not an ordinary, smooth line; as its order increases, it continuously curves, folds back, enters smaller regions, folds back again, enters even smaller regions, and so on. When this process continues infinitely, it establishes a continuous mapping from a one-dimensional parameter to two-dimensional space. Consequently, an object that appears “one-dimensional” is able to cover the entire two-dimensional square.
But this does not mean that “dimension has vanished.”
There is a common point of confusion here. The Hilbert curve does not imply that “there is absolutely no difference between one dimension and two dimensions”—far from it. What it actually demonstrates is that points on an interval can cover a two-dimensional square via a continuous mapping, yet this mapping is not one-to-one; in other words, different curve parameters may sometimes correspond to the same spatial location. Thus, it does not mean that an ordinary piece of string in the real world suddenly transforms into a square, but rather that such a highly specific type of continuous mapping exists in mathematics.
Why do mathematicians study things like this?
The Hilbert curve was not created merely to produce beautiful mathematical art; it emerged from mathematicians' research into the relationship between continuous curves and space.
In the late 19th century, German mathematician David Hilbert proposed this space-filling curve, which challenged people's intuition regarding the relationship between lines and surfaces.
To the average person, a line is a line and a surface is a surface—they seem like completely distinct entities.
However, the Hilbert curve reveals that 'dimensions' in the mathematical world can sometimes exhibit highly counter-intuitive relationships.
The Hilbert curve is not just a mathematical construct designed to challenge intuition; it has practical applications, such as mapping data from a two-dimensional space onto a one-dimensional sequence.
For instance, imagine you have a 2D map, but a computer needs to store the data in a linear address space. The question then arises: How can we ensure that data points located near each other in 2D space are also placed close together in the 1D sequence?
The Hilbert curve offers an excellent ordering method because it possesses strong spatial locality. Simply put, regions that are close to one another in 2D space generally remain close when ordered along the Hilbert curve. This means that the original 2D spatial relationships are largely preserved within the 1D arrangement.
This concept is applicable to a wide range of computer science fields, including spatial databases, data indexing, image processing, computer graphics, scientific computing, and multidimensional data processing.
Thus, this curve—which might look like a mere mathematical novelty—actually has deep connections to computer science.
The Limits of a Line
Now, let’s return to the initial question: How can a single line possibly fill a square?
The answer provided by the Hilbert curve isn't that 'an ordinary line literally transforms into a surface.' Instead, it begins with a simple curve and—using the curve from the previous iteration as the foundation for the next—continuously refines the space through scaling, rearranging, rotating/flipping, and connecting segments.
As this process continues infinitely, the continuous curve can cover the entire square. This sounds highly counterintuitive, yet it is precisely this quality that makes it one of the most famous space-filling curves in mathematics.
If we distill the story of the Hilbert curve, it is actually quite simple: A simple curve → scaled down into multiple parts → rearranged → rotated/flipped → connected → resulting in the next iteration → using the previous iteration as the foundation for the next → repeated continuously → the curve becomes increasingly dense → gaps shrink → infinite refinement → the entire space is filled.
A rule so simple it is almost hard to believe ultimately yields an astonishing result: A continuous curve capable of traversing a two-dimensional space. This is the Hilbert curve.
What is the difference between the Hilbert curve and the Dragon curve?
If you have already explored the Dragon curve, you might think: 'They both look like curves generated through continuous recursion.'
That is true, but what they aim to demonstrate is different.
The core of the Dragon curve is continuous folding. A simple line transforms into a complex fractal structure through repeated folding. It shows us the transition from simple rules to complex patterns.
The core of the Hilbert curve is continuous subdivision and space-filling. A continuous line undergoes constant refinement, rearrangement, and connection to eventually cover a two-dimensional area. It shows us the transition from a single curve to the entire 2D space.
So, you can simply think of it this way:
The Dragon curve is about folding a dragon into shape.
The Hilbert curve is about using a single line to traverse an entire room.
What is the difference between the Hilbert curve and the Mandelbrot set?
Both the Hilbert curve and the Mandelbrot set can generate surprisingly complex structures from simple rules, yet the ways in which they create this complexity are completely different.
The Mandelbrot set is generated through a continuous process of complex number → iteration → evaluation, resulting in a complex set; its most captivating feature is the continuous emergence of intricate details upon infinite magnification.
The Hilbert curve is generated by repeatedly performing scaling down → arranging → rotating/flipping → connecting → repeating, ultimately increasing the curve's spatial coverage density.
In short:
The Mandelbrot set: Explores infinite detail.
The Hilbert curve: Explores infinite density.
While both produce complex visual structures, the experience of exploring them is entirely different.
Continue Exploring the World of Mathematics
The Hilbert curve is a unique construction in the realms of fractal and recursive geometry.
If you enjoy mathematical figures where simple rules repeat to create complex structures, you might also explore the Dragon Curve to see how a simple line transforms into an intricate fractal pattern through repeated folding. You could also look at the Apollonian Gasket to see how circles fill the gaps between one another, creating a seemingly endless world of circles. Or, revisit the Mandelbrot Set to see how the iteration of a simple complex number generates an infinitely complex boundary.
Although their mathematical principles differ, they all reveal something fascinating: repeating a simple rule can sometimes lead us into a world that completely defies intuition.
The Hilbert curve offers a particularly surprising answer: sometimes, a line can not only become incredibly complex but can also traverse an entire space in its own unique way.
You can continue to explore more amazing mathematical figures or read more about the Hilbert curve on Wikipedia.