The curve that broke a 19th-century assumption
In 1890, Giuseppe Peano stunned mathematicians by constructing a continuous curve that passes through every single point of a filled square — a one-dimensional object, parametrised by a single real variable t, with a range that covers a genuinely two-dimensional area. Before Peano's construction, most mathematicians assumed a continuous curve simply couldn't have positive area; dimension seemed like an obviously invariant, intuitive property. Peano's curve, and David Hilbert's better-known 1891 variant, showed that continuity alone permits far stranger behaviour than intuition suggested.
The 3×3 boustrophedon rule
Peano's original construction divides the unit square into a 3×3 grid of nine sub-squares and visits them in a boustrophedon ("as the ox plows") order — left to right along the bottom row, then right to left along the middle row, then left to right along the top row again — so that consecutive sub-squares always share an edge, keeping the path continuous. Each of those nine sub-squares is then recursively subdivided and traced the same way, alternating the orientation of the boustrophedon pass (sometimes flipped, sometimes mirrored) so that the sub-curve endpoints always connect smoothly to their neighbours across the whole recursive structure.
function peano(x, y, size, level, flip) {
if (level === 0) { drawTo(x + size/2, y + size/2); return; }
const s = size / 3;
const order = flip ? [2,1,0] : [0,1,2]; // boustrophedon row order, alternated
for (const row of order) {
const colOrder = (row % 2 === 0) ? [0,1,2] : [2,1,0];
for (const col of colOrder)
peano(x + col*s, y + row*s, s, level - 1, !flip);
}
}
Filling space without crossing itself
At every recursion level, the number of sub-squares visited is 9^level, and as the level increases the curve's path passes arbitrarily close to every point of the square. In the strict mathematical limit (infinite recursion), the curve's image genuinely equals the entire filled square — a curve of topological dimension 1 whose range has Lebesgue measure equal to the full 2D area, i.e. a set with Hausdorff dimension exactly 2. This does not contradict Peano's curve being continuous: continuity only guarantees that nearby parameter values t map to nearby points, not that the curve can't be space-filling; it's the topological dimension of the domain (an interval, dimension 1) versus the dimension of the range (the whole square) that people intuitively — and wrongly — assumed had to match.
Peano vs Hilbert vs Z-order: which space-filling curve to use
Peano's original curve uses base-3 subdivision (3×3 grids); Hilbert's 1891 curve uses base-2 subdivision (2×2 grids) and has become the far more common choice in computing, because Hilbert curve locality — points close together along the 1D parametrisation stay close together in 2D space, and vice versa — is noticeably better than Peano's or the even simpler Z-order (Morton) curve, which also subdivides into quadrants but in a fixed corner order that produces occasional large jumps between consecutive cells. That locality property is why Hilbert-curve ordering shows up in real systems: database spatial indexes that want range queries to touch few disk pages, image processing algorithms that want cache-friendly pixel traversal, and dithering algorithms that want error diffusion to stay spatially local. Peano's curve, being the historical first, is less used in practice but is the direct ancestor of the whole family.
Space-filling curves as a dimension-reduction trick
Because a space-filling curve gives a continuous (though not smooth, and not one-to-one — points can be visited more than once) surjection from a 1D interval onto a 2D (or higher-dimensional) region, it provides a genuine way to convert multi-dimensional data into a single ordered sequence while preserving a meaningful notion of "nearness." This is exploited well beyond pure recreation: load-balancing algorithms that partition a 2D or 3D simulation domain across processors often walk a Hilbert curve to assign contiguous chunks of curve-length to each processor, guaranteeing that each processor's region stays spatially compact, which minimises the communication needed between processors at chunk boundaries.
A note on "dimension" itself
Peano's curve is part of why mathematicians eventually needed multiple, more careful definitions of dimension — topological dimension (which stays 1 for any curve, space-filling or not, because locally it still looks like a line) versus Hausdorff or fractal dimension (which measures how a set's "size" scales under magnification, and gives Peano's curve's image a dimension of 2, matching the area it fills). The same distinction, applied to sets with dimension strictly between integers, is what gives fractals like the Sierpinski carpet or the dragon curve boundary their famous non-integer dimensions.
Frequently asked questions
How can a curve have zero width but still fill an entire area?
The curve is continuous but not one-to-one - as the recursion depth goes to infinity, it passes through every point of the square, sometimes revisiting points, without ever having positive width itself. Its parametrising domain (an interval) has topological dimension 1, but its image (the filled square) has Hausdorff dimension 2 - continuity permits this even though it defies naive intuition about curves.
Is the Peano curve the same as the Hilbert curve?
No. Peano's original 1890 curve subdivides each square into a 3x3 grid; Hilbert's 1891 curve subdivides into a 2x2 grid instead. Hilbert's version has better locality (nearby points on the curve stay nearby in the square) and is the one almost universally used in computing applications like spatial database indexing.
Why does the locality property of a space-filling curve matter in practice?
Locality means two points close together along the curve's 1D parameter also tend to be close together in the 2D or 3D region it fills, and vice versa. That property is exploited by spatial database indexes, cache-friendly image processing, and parallel-computing load-balancing algorithms that all want to convert multi-dimensional data into an ordered sequence without destroying spatial nearness.
Try it live
Everything above runs in your browser — open Peano Space-Filling Curve and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Peano Space-Filling Curve simulation