The optimal fiscal stabilization rule presented in this paper is derived from a loss function where the government is assumed to keep the structural balance close to its target level and simultaneously stabilize the GDP and inflation gaps. The rule yields the size of the discretionary stabilization measures needed, in addition to automatic stabilizers, to be able to stabilize the business cycle, without compromising the sustainability of public finances. Using this policy rule and a first-order Taylor expansion of the fiscal balance, we decompose the automatic stabilizers and the discretionary fiscal policy conditional on business cycle conditions.