fizzbloom

Menger Sponge

Carve a cube into a sponge with endless surface and almost no volume.

Menger Sponge: preview of the 3D scene

How to play

  • Pull the brass lever on the plinth to carve the cube one level deeper, or push it back.
  • Tap a hole to dive towards it. Tap again to go further in, or tap empty space to back out.
  • Drag to walk round the sponge. Look straight at a face and it settles square to you.
  • Open Lab for the Infinite lattice, fly mode and other materials. The readouts count cubes, volume and area.

Challenges

  1. Pull the lever to carve the cube to level 3: 8,000 little cubes
  2. Look straight at one face to find a Sierpiński carpet
  3. Tap a hole to dive in, and look out from inside the sponge

Try this

  • Pull the lever from level 1 to level 5 and watch the volume readout fall to 20/27 of its value each time.
  • Open the Lab, turn on the infinite lattice and fly down a tunnel: the same pattern repeats forever in every direction.
  • Watch the surface-area readout. It keeps growing at every level, even as the solid itself all but vanishes.

Fun facts

  • The Austrian mathematician Karl Menger described the sponge in 1926.
  • Each step keeps 20 of the 27 smaller cubes, so after n steps 20ⁿ cubes remain.
  • The sponge’s fractal dimension is log 20 / log 3, about 2.727: more than a surface, but less than a solid.
  • Each face of the Menger sponge is a Sierpiński carpet.

A solid with no volume and endless surface

Start with a cube. Divide it into 27 smaller cubes, like a 3×3 puzzle cube, and remove seven of them: the one in the very middle and the one in the centre of each face. Twenty cubes remain, with a square tunnel running straight through the middle in every direction. Now do the same to each of the twenty smaller cubes, and again to each of theirs, forever. What is left is the Menger sponge.

Vanishing volume

Each step keeps 20 of every 27 pieces, so the volume shrinks to 20/27 of its previous value. After one step about 74% of the cube remains; after five steps about 22%; after twenty steps less than 0.3%. Repeat forever and the volume falls to zero, even though the sponge never falls apart into separate pieces.

Endless surface

Every hole you carve exposes new walls inside the tunnels, so the surface area keeps growing. For a unit cube the area at level n is 2(20/9)ⁿ + 4(8/9)ⁿ, which goes up without limit. The finished sponge has no volume at all and infinite surface. The Lab shows the area as a multiple of the original cube’s six faces.

A fractional dimension

Shrink the sponge by a factor of three and you need 20 copies to rebuild it. For an ordinary solid you would need 27 = 3³ copies, for a flat square 9 = 3², for a line 3 = 3¹. The exponent is the dimension, so the sponge’s dimension d satisfies 3d = 20, giving d = log 20 / log 3 ≈ 2.727. It is a fractal: more than a surface, less than a solid. Each of its faces is a Sierpiński carpet, a famous flat fractal, and Menger showed that the sponge contains a copy of every possible curve, which is why it is also called the Menger universal curve.

How it is drawn

The sponge is drawn by ray marching. For any point in space a short formula gives the exact distance to the nearest piece of sponge: it folds space into one small cube, measures the distance to the cross-shaped holes at each level, and keeps the largest. Each ray steps forward by that distance until it touches the surface. Light falls off down the tunnels, so each level of carving reads as a deeper shadow.

For the curious

After n levels: cubes = 20ⁿ, volume = (20/27)ⁿ, surface area = 2(20/9)ⁿ + 4(8/9)ⁿ for a unit cube. The infinite lattice repeats the sponge in every direction with period 2, which you can see in the code as p = mod(p + 1, 2) − 1, so the tunnels never end.

Questions people ask

What is a Menger sponge?

It is a fractal made by dividing a cube into 27 smaller cubes, removing the middle one and the middle of each face, and repeating the process on every remaining cube forever.

Does the Menger sponge have zero volume?

In the limit, yes. Each step keeps 20/27 of the volume, so after infinitely many steps nothing is left by volume, yet the shape stays connected and its surface area becomes infinite.

What is the dimension of the Menger sponge?

Its fractal dimension is log 20 / log 3, about 2.727, because shrinking it by a factor of three takes 20 copies to rebuild it, compared with 27 for a solid cube.