In this study, we employ a rigorously established mathematical foundation rooted in perturbation theory in general relativity, particularly within the gauge-invariant framework devised by Nakamura, we have derived perturbation equations at both first and second orders for arbitrary backgrounds in f(R) theories of gravity. These equations are used in the context of cosmology, especially when dealing with first-order perturbations in f(R). Within this framework, we have successfully formulated gauge-invariant linear equations for scalar, vector, and tensor perturbations. This generalized formulation not only provides a comprehensive perspective on perturbations but also outlines a systematic approach for transitioning to specific gauges. Consequently, we have obtained and analyzed specific gauges, such as the Newtonian and synchronous gauges, within this formalism, and we have subsequently compared our findings with existing results in the literature. We provide a map of implications and future work of this formulation. locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon Physics Subject Headings (PhySH)Alternative gravity theoriesEvolution of the UniverseRelativistic aspects of cosmology