Analytic results for the stability of resistive ballooning modes ͑RBMs͒ and electron inertial ballooning modes are obtained using a two-scale analysis. This work generalizes previous calculations used for axisymmetric ŝ − ␣ geometry ͓R. H. Hastie, J. J. Ramos, and F. Porcelli, Phys. Plasmas 10, 4405 ͑2003͔͒ to general three-dimensional geometry. A unified theory is developed for RBMs and inertial ballooning modes, in which the effects of both ideal magnetohydrodynamic free energy ͑as measured by the asymptotic matching parameter ⌬Ј͒ and geodesic curvature drives in the nonideal layer are included in the dispersion relation. This unified theory can be applied to determine the stability of drift-resistive-inertial ballooning modes in the low temperature edge regions of tokamak and stellarator plasmas where steep density gradients exist.