When is it optimal for a government to default on its legal repayment oblig- ations? We answer this question for a small open economy with domestic production risk in which the government optimally finances itself by issuing non-contingent debt. We show that Ramsey optimal policies occasionally devi- ate from the legal repayment obligation and repay debt only partially, even if such deviations give rise to significant default costs. Optimal default improves the international diversification of domestic output risk, increases the efficiency of domestic investment and - for a wide range of default costs - significantly increases welfare relative to a situation where default is simply ruled out from Ramsey optimal plans. We show analytically that default is optimal following adverse shocks to domestic output, especially for very negative international wealth positions. A quantitative analysis reveals that for empirically plausible wealth levels, default is optimal only in response to disaster-like shocks to do- mestic output, and that default can be Ramsey optimal even if the net foreign asset position is positive.