One rule, applied recursively
The Menger sponge, first described by Austrian mathematician Karl Menger in 1926, starts from a single solid cube and applies one recursive carving rule: divide the cube into a 3×3×3 grid of 27 equal sub-cubes, remove the sub-cube at the very centre of the whole cube along with the six sub-cubes centred on each face, and keep the remaining 20 corner-and-edge sub-cubes. Then apply the exact same rule to each of those 20 survivors, and repeat forever.
level 0: 1 solid cube level 1: 27 sub-cubes → remove 1 centre + 6 face-centres → keep 20 level 2: each of those 20 repeats the same 27-minus-7 rule → 400 cubes level n: 20^n cubes remain, each of side length 3^-n × the original
Vanishing volume, infinite surface
Every recursion level keeps 20 of the previous level's 27 sub-cubes, so the fraction of volume retained multiplies by 20/27 at every level. That fraction is less than 1, so as the recursion continues without bound the sponge's total volume shrinks toward zero — in the true mathematical limit, an infinitely recursed Menger sponge has no volume at all. At the same time, every subdivision step exposes new interior faces along every tunnel that gets carved out, so the total surface area grows without bound at every level. The Menger sponge is the three-dimensional embodiment of a shape that is simultaneously nothing, in volume, and infinite, in surface area.
A fractional dimension
Ordinary solids have integer dimension: a line is 1-dimensional, a filled square is 2-dimensional, a filled cube is 3-dimensional. The Menger sponge sits in between, and its Hausdorff dimension can be computed directly from the recursive construction rule: each step scales lengths down by a factor of 3 and produces 20 self-similar copies of the previous stage, and for a self-similar fractal built this way the dimension is
D = log(N) / log(1/s) N = number of self-similar copies per step = 20 s = the linear scale factor applied to each copy = 1/3 D = log(20) / log(3) ≈ 2.7268
A dimension of about 2.73 says something concrete: the sponge is more substantial than any flat surface (dimension 2) but never fills up space the way a solid cube does (dimension 3) — it is a shape whose complexity genuinely falls between a surface and a solid, not metaphorically but by the precise scaling measure that defines fractal dimension.
The 2D and 1D relatives
The same carving idea one dimension down produces the Sierpinski carpet: divide a square into a 3×3 grid of 9 sub-squares, remove the centre one, recurse on the remaining 8. Its dimension is log(8)/log(3) ≈ 1.8928. One dimension further down, applying an analogous removal rule to a line segment gives the Cantor set, dimension log(2)/log(3) ≈ 0.6309. The Menger sponge, Sierpinski carpet and Cantor set form a single family across three, two and one dimensions, each generated by removing the same relative structure and each with a dimension you can compute from the identical log(N)/log(1/s) formula.
Rendering it: raymarching a signed distance function
Explicitly building a mesh for a Menger sponge past a few recursion levels is impractical — level 5 alone has 20^5, over three million, individual cube pieces — so it is rendered the same way as the other fractal geometry on this site, by raymarching a signed distance function. At each sample point, the distance-estimation routine folds the point's coordinates back through the cube-and-cross removal test at every recursion level up to the chosen maximum, without ever materialising the geometry as explicit triangles, and a camera ray is advanced step by step using that distance estimate until it converges on the surface. This lets the simulation push the recursion level as high as five or six and stay interactive, something an explicit-mesh approach could never do at the same detail.
Frequently asked questions
Does the Menger sponge have any volume left after infinite recursion?
In the mathematical limit, no. Each recursion level keeps 20 of the previous level's 27 sub-cubes, a fraction of 20/27 less than 1, and multiplying that fraction infinitely many times drives the retained volume to zero, even though the shape never disappears and its surface area grows without bound.
What does a fractal dimension of 2.73 actually mean?
It means the shape's complexity, measured by how its detail scales as you zoom in, sits between that of a flat surface (dimension 2) and a solid volume (dimension 3). It is computed directly from the construction rule: log(20)/log(3), since each recursion step produces 20 self-similar copies at one third the previous linear scale.
How is the Menger sponge related to the Sierpinski carpet?
They are the same recursive removal idea at different dimensions: the carpet removes the centre of a 3×3 grid of squares (keeping 8 of 9, dimension log(8)/log(3)), the sponge removes the centre cross of a 3×3×3 grid of cubes (keeping 20 of 27, dimension log(20)/log(3)). The Cantor set is the same idea again, one dimension further down, on a line segment.
Try it live
Everything above runs in your browser — open Menger Sponge and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Menger Sponge simulation