We study the Misner-Sharp mass for the $f(R)$ gravity in an $n$-dimensional (n$geq$3) spacetime which permits three-type $(n-2)$-dimensional maximally symmetric subspace. We obtain the Misner-Sharp mass via two approaches. One is the inverse unified first law method, and the other is the conserved charge method by using a generalized Kodama vector. In the first approach, we assume the unified first still holds in the $n$-dimensional $f(R)$ gravity, which requires a quasi-local mass form (We define it as the generalized Misner-Sharp mass). In the second approach, the conserved charge corresponding to the generalized local Kodama vector is the generalized Misner-Sharp mass. The two approaches are equivalent, which are bridged by a constraint. This constraint determines the existence of a well-defined Misner-Sharp mass. As an important special case, we present the explicit form for the static space, and we calculate the Misner-Sharp mass for Clifton-Barrow solution as an example.