The transition from economic stagnation to sustained growth is often modelled thanks to "population-induced" productivity improvements, which are assumed rather than derived from primary assumptions. In this paper the effect of population on productivity is derived from optimal behavior. More precisely, both the number and location of education facilities are chosen optimally by municipalities. Individuals determine their education investment depending on the distance to the nearest school, and also on technical progress and longevity. In this setting, higher population density enables the set-up costs of additionalschools to be covered, opening the possibility to reach higher educational levels. Using counterfactual experiments we find that one third of the rise in literacy can be directly attributed to the effect of density, while one sixth is linked to higher longevity and one half to technical progress. Moreover, the effect of population density in the model is consistent with the available evidence for England, where it is shown that schools were established at a high rate over the period 1540-1620.