The authors prove an inequality for sums, which generalizes both Landau's sharpening of Carlson's inequality and the corresponding complementary result by Levin and Ste\v{c}kin. The inequality is optimal, in the sense that necessary and sufficient conditions on the parameters for which the inequality holds are given. In some cases, sharp constants are obtained, also in situations not covered by the classical results.