We describe a model for calculating the optimal quantity of debt and then apply it to the U.S. economy. The model consists of a large number of infinitely-lived households whose saving behavior is influenced by precautionary saving motives and borrowing constraints. This model incorporates a different role for government debt than the standard representative agent growth model and captures different trade-offs between the benefits and costs of varying its level. Government debt enhances the liquidity of households by providing additional assets for smoothing consumption (in addition to claims to capital) and effectively loosening borrowing constraints. By raising the interest rate, government debt makes assets less costly to hold and more effective in smoothing consumption. However, the implied taxes have wealth distribution, incentive, and insurance effects. Further, government debt crowds out capital (via higher interest rates) and lowers per capita consumption. Our quantitative analysis suggests that the crowding out effect is decisive for welfare. We also describe variations of the model which permit endogenous growth. It turns out that even with lump sum taxes and inelastic labor, government debt as well as government consumption have growth rate effects, thereby implying large welfare gains from reducing the level of debt.