This paper proposes a quantitative theory of the interaction between private and public debt in an open economy. Excessive private debt increases the frequency of financial crises. During such crises the government provides fiscal bailouts financed with risky public debt. This response may cause a sovereign debt crisis, which is characterized by a higher probability of a sovereign default. The model is quantitatively consistent with the evolution of private debt, public debt, and sovereign spreads in Spain from 1999 to 2015, and provides an estimate of the degree of overborrowing, its effect on the spreads, and the optimal macroprudential policy.