Abstract: Financial connections hedge risks, but also propagate large shocks. We characterise socially optimal financial networks in the presence of this tradeoff. These networks divide banks into groups, with strong connections within groups but weak connections between groups. The weak connections create firebreaks, which limit the spread of contagion. When financial distress costs are below a certain threshold, socially efficient networks cannot form in equilibrium. Shareholders engage in risk-shifting by altering financial connections—thereby increasing equity value, but also raising the likelihood of contagion. Equally, socially efficient networks are an equilibrium when financial distress costs are above this threshold. Contagion becomes so costly that banks are not willing to take the other side of a risk-shifting trade.