Context. A magnetic cloud (MC) is a magnetic flux rope in the solar wind (SW), which, at 1 AU, is observed ∼2-5 days after its expulsion from the Sun. The associated solar eruption is observed as a coronal mass ejection (CME). Aims. Both the in situ observations of plasma velocity distribution and the increase in their size with solar distance demonstrate that MCs are strongly expanding structures. The aim of this work is to find the main causes of this expansion and to derive a model to explain the plasma velocity profiles typically observed inside MCs. Methods. We model the flux rope evolution as a series of force-free field states with two extreme limits: (a) ideal magnetohydrodynamics (MHD) and (b) minimization of the magnetic energy with conserved magnetic helicity. We consider cylindrical flux ropes to reduce the problem to the integration of ordinary differential equations. This allows us to explore a wide variety of magnetic fields at a broad range of distances to the Sun. Results. We demonstrate that the rapid decrease in the total SW pressure with solar distance is the main driver of the flux-rope radial expansion. Other effects, such as the internal over-pressure, the radial distribution, and the amount of twist within the flux rope have a much weaker influence on the expansion. We demonstrate that any force-free flux rope will have a self-similar expansion if its total boundary pressure evolves as the inverse of its length to the fourth power. With the total pressure gradient observed in the SW, the radial expansion of flux ropes is close to self-similar with a nearly linear radial velocity profile across the flux rope, as observed. Moreover, we show that the expansion rate is proportional to the radius and to the global velocity away from the Sun. Conclusions. The simple and universal law found for the radial expansion of flux ropes in the SW predicts the typical size, magnetic structure, and radial velocity of MCs at various solar distances.