We study generalized Misner-Sharp energy in f (R) gravity in a spherically symmetric spacetime. We find that unlike the cases of Einstein gravity and Gauss-Bonnet gravity, the existence of the generalized Misner-Sharp energy depends on a constraint condition in the f (R) gravity. When the constraint condition is satisfied, one can define a generalized Misner-Sharp energy, but it cannot always be written in an explicit quasi-local form. However, such a form can be obtained in a FRW universe and for static spherically symmetric solutions with constant scalar curvature. In the FRW universe, the generalized Misner-Sharp energy is nothing but the total matter energy inside a sphere with radius r, which acts as the boundary of a finite region under consideration. The case of scalar-tensor gravity is also briefly discussed.