We study which types of activities migrate to the shadow banking sector, why migration occurs in some sectors, and not others, and the quantitative importance of this migration. We explore this question in the $10 trillion US residential mortgage market, in which shadow banks account for more than half of new lending. Using micro data, we document a large degree of market segmentation in shadow bank penetration. They substitute for traditional — deposit taking — banks in easily securitized lending, but are limited from engaging in activities requiring on-balance sheet financing. Traditional banks adjust their financing and lending activities to balance sheet shocks, and behave more like shadow banks following negative shocks. Motivated by this evidence, we build a structural model. Banks and shadow banks compete for borrowers. Banks face regulatory constraints, but benefit from the ability to engage in balance sheet lending. Like shadow banks, banks can choose to access the securitization market. To evaluate distributional consequences, we model a rich demand system with income and house price differences across borrowers. The model is estimated using spatial pricing rules and bunching at the regulatory threshold for identification. We study the consequences of capital requirements, access to securitization market, and unconventional monetary policy on lending volume and pricing, bank stability and the distribution of consumer surplus across rich and poor households. Disruptions in securitization markets rather than capital requirements have the largest quantitative impact on aggregate lending volume and pricing.