We develop a framework that integrates natural advantage, agglomeration economies and firm selection to explain why large cities are both more productive and more unequal than small towns. Our model highlights complementarities among those factors and matches a number of key stylised facts about cities. A larger city size increases productivity via selection and higher urban productivity provides incentives for rural–urban migration. Tougher selection increases the returns to skills and earnings inequality in cities. We illustrate a multi-city version of the model numerically and explore the formation of new cities, the growth of existing cities and changes in income inequality.