The distribution of firms in space is far from uniform. Some locations host the most productive large firms, while others barely attract any. In this paper, I study the sorting of heterogeneous firms across locations. I first propose a theory of the distribution of heterogeneous firms in a variety of sectors across cities. Aggregate TFP and welfare depend on the extent of agglomeration externalities produced in cities and on how heterogeneous firms sort across them. The distribution of city sizes and the sorting patterns of firms are uniquely determined in equilibrium. This allows me to structurally estimate the model, using French firm-level data. I find that nearly two thirds of the observed productivity advantage of large cities is due to firm sorting. I use the estimated model to quantify the general equilibrium e↵ects of place-based policies, designed to attract firms to particular regions. I find that policies that decrease local congestion lead to a new spatial equilibrium with higher aggregate TFP and welfare. In contrast, policies that subsidize smaller cities have negative aggregate e↵ects. ⇤email@example.com. I am extremely grateful to Esteban Rossi-Hansberg, Steve Redding and Gene Grossman for continuous support and guidance. I also thank Treb Allen, Costas Arkolakis, Thomas Chaney, Don Davis, Jan De Loecker, Gilles Duranton, Pablo Fajgelbaum, Joshua Gottlieb, Pat Kline, Oleg Itskhoki, Kiminori Matsuyama, Eduardo Morales, Dávid Nagy, Andrés Rodŕıguez-Clare, Felix Tintelnot and Jonathan Vogel as well as numerous seminar and conference participants for helpful discussions and comments. This research benefited from financial support from the International Economics Section at Princeton University.