Societies often rely on simple monetary and fiscal rules to restrict the size and behavior of governments. I study the merit of these constraints in a dynamic stochastic model in which fiscal and monetary policies are jointly determined. For all types of shocks considered, the best rule is a limit on the primary deficit. Most welfare gains arise from constraining government behavior during normal times, which to a large extent is sufficient to discipline policy in adverse times. Monetary policy rules are not generally desirable as they severely hinder distortion-smoothing. Debt ceilings are generally benign, but always dominated by deficit rules. For an economy calibrated to the postwar U.S., the optimal rule is a primary surplus of roughly half a percent of output.