We find the optimal target values for fiscal rules and measure their aggregate effects using a model of sovereign default. We calibrate the model to an economy that pays a significant sovereign default premium when the government is not constrained by fiscal rules. For different levels of the default premium, we find that a government with a debt of 38 percent of trend income (typical in the case studied here) chooses to commit to a debt ceiling of 30 percent of trend income that starts being enforced four years after its announcement. This rule generates expectations of lower future indebtedness, and thus it allows the government to borrow at interest rates significantly lower than the ones it pays without a rule. We also study the case in which the government conducts a voluntary debt restructuring to capture the capital gains from the increase in its debt market value implied by the existence of a fiscal rule. In this case, the government is found to choose instead a debt ceiling of 25 percent of trend income that starts being enforced less than two years after its announcement. After the imposition of the debt ceiling, lower debt levels allow the government to implement a less procyclical fiscal policy that reduces consumption volatility. However, the government prefers a procyclical debt ceiling that implies a larger reduction of the default probability at the expense of a higher consumption volatility.