This paper proposes a theory of optimal public expenditure when unemployment is inefficient. The theory is based on a matching model. Optimal public expenditure deviates from the Samuelson rule to reduce the unemployment gap (the difference between current and efficient unemployment rates). Such optimal “stimulus spending” is described by a formula expressed with three sufficient statistics: the unemployment gap, the unemployment multiplier (the decrease in unemployment achieved by increasing public expenditure), and the elasticity of substitution between public and private consumption. When unemployment is inefficiently high and the multiplier is positive, the formula yields the following results. (a) Optimal stimulus spending is positive and increasing in the unemployment gap. (b) Optimal stimulus spending is zero for a zero multiplier, increasing in the multiplier for small multipliers, largest for a moderate multiplier, and decreasing in the multiplier beyond that. (c) Optimal stimulus spending is zero if extra public goods have no value, it becomes larger as the elasticity of substitution increases, and it completely fills the unemployment gap if extra public goods are as valuable as extra private goods.