On this page
In 1890 Giuseppe Peano published a four-page paper with a title that sounds impossible: a curve that fills a whole plane area (Sur une courbe, qui remplit toute une aire plane, Mathematische Annalen, volume 36, pages 157 to 160). How can a line become a square? Below you will draw the answer and number a grid the way a database does.
What is a space-filling curve?
Since Camille Jordan's definition of 1887, a curve has meant a continuous function from the interval [0, 1] into the plane, as the Wikipedia survey of space-filling curves sets out. Think of t as time and f(t) as the position of a moving pen. A space-filling curve is one whose pen has visited every point of the unit square by t = 1.
Peano was following up a surprise from Georg Cantor, who had shown that a segment and a square contain the same number of points. Cantor's matching jumps about wildly; Peano asked whether a continuous one could exist. For a warm-up, read our post on the Cantor set, with length zero yet uncountably many points. Peano's paper has no pictures; it works with base-3 digits.
How do you draw the Hilbert curve?
A year later, David Hilbert published a variation in the same journal (volume 38, pages 459 to 460). It was the first to include a picture; the image above shows the first three stages.
Stage 1: split the square into 4 cells and join their centres in an upside-down U: up, right, down.
Stage 2: split every cell into 4, making 16 cells. Put a half-size copy of stage 1 in each quarter. Reflect the bottom two copies across a diagonal so the pieces join end to end.
Stage 3: repeat to get 64 cells. Stage n has 4^n cells, each of side 1/2^n.
The Hilbert curve is the limit of these pictures. Every point of the square lies in some cell of every stage, so the limit leaves no point out. Stage n has length (4^n − 1)/2^n (1.5, 3.75, 7.875), so the length grows without limit, and the image is the whole square, of dimension 2 by box counting.
Why is the limit continuous but not one-to-one?
Continuous. At stage n, the times between k/4^n and (k+1)/4^n are spent inside the k-th cell, and later stages only redraw the path inside that cell. Two times less than 1/4^n apart therefore land in the same cell or in two neighbouring cells, at most √5/2^n apart. The pen never jumps.
Not one-to-one. The first quarter of the time fills the bottom-left quarter of the square, and the second quarter of the time fills the top-left quarter. These two closed quarters share an edge, so every point on that edge is reached in both stretches of time. Apart from the single point the pen reaches at exactly t = 1/4, each of them is visited at two different times.
No cleverer curve avoids this, as the Wikipedia survey explains: a continuous one-to-one map from [0, 1] onto the square would preserve shape both ways, yet removing one inside point splits a segment in two and leaves a square in one piece. That survey also notes that no space-filling curve is differentiable; compare Weierstrass's continuous but nowhere differentiable function.
The Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing, so if continuity or limits feel shaky, start there.
Where are Hilbert curves used today?
A disk stores data along one line of addresses, so to store map points you can number cells along a Hilbert curve and sort by that number. Moon, Jagadish, Faloutsos and Saltz (2001) analysed how well this keeps neighbours together. Their formulas agree with experiments: the number of separate runs (clusters) a query touches depends on the surface area of the query region (for a flat map query, the length of its boundary), not on its volume (its area). They also showed that the Hilbert curve clusters better than the Z curve.
For printing, Velho and Gomes (1991) used space-filling curves for digital halftoning: aperiodic clustered dots whose cluster size can change in one-pixel steps.
Worked example: number a 4 × 4 grid and test locality
The stage-2 Hilbert numbers, from the bottom-left cell:
Top row: 5, 6, 9, 10
Third row: 4, 7, 8, 11
Second row: 3, 2, 13, 12
Bottom row: 0, 1, 14, 15
Now check three things.
Consecutive numbers are always side-by-side neighbours: trace 0 to 15 without lifting the pencil or moving diagonally.
Neighbours do not always get close numbers: cells 2 and 13 touch across the middle line.
Range queries: the bottom-left 2 × 2 box holds cells 0 to 3, one run. The centre 2 × 2 box holds 2, 7, 8 and 13, three runs: {2}, {7, 8} and {13}. These runs are what Moon and colleagues counted.
Next, number the 64 cells of stage 3 and check that rule 1 still holds. If a continuity step trips you up, the Fermi Problem Library has a step-by-step solver that explains the reasoning.



