Electrons moving through a spatially periodic lattice potential develop a quantized energy spectrum consisting of discrete Bloch bands. In two dimensions, electrons moving through a magnetic field also develop a quantized energy spectrum, consisting of highly degenerate Landau energy levels. When subject to both a magnetic field and a periodic electrostatic potential, two-dimensional systems of electrons exhibit a self-similar recursive energy spectrum. Known as Hofstadter's butterfly, this complex spectrum results from an interplay between the characteristic lengths associated with the two quantizing fields, and is one of the first quantum fractals discovered in physics. In the decades since its prediction, experimental attempts to study this effect have been limited by difficulties in reconciling the two length scales. Typical atomic lattices (with periodicities of less than one nanometre) require unfeasibly large magnetic fields to reach the commensurability condition, and in artificially engineered structures (with periodicities greater than about 100 nanometres) the corresponding fields are too small to overcome disorder completely. Here we demonstrate that moiré superlattices arising in bilayer graphene coupled to hexagonal boron nitride provide a periodic modulation with ideal length scales of the order of ten nanometres, enabling unprecedented experimental access to the fractal spectrum. We confirm that quantum Hall features associated with the fractal gaps are described by two integer topological quantum numbers, and report evidence of their recursive structure. Observation of a Hofstadter spectrum in bilayer graphene means that it is possible to investigate emergent behaviour within a fractal energy landscape in a system with tunable internal degrees of freedom.