Recent works have shown that the domain walls of room-temperature multiferroic BiFeO3 (BFO) thin films can display distinct and promising functionalities. It is thus important to understand the mechanisms underlying domain formation in these films. High-resolution x-ray diffraction and piezo-force microscopy, combined with first-principles simulations, have allowed us to characterize both the atomic and domain structure of BFO films grown under compressive strain on (001)-SrTiO3, as a function of thickness. We derive a twining model that describes the experimental observations and explains why the 71o domain walls are the ones commonly observed in these films. This understanding provides us with a new degree of freedom to control the structure and, thus, the properties of BiFeO3 thin films.