$$ P_AO_2 = FiO_2 \left( P_{ATM} - P_{H_2O} \right) - \left( \frac{PaCO_2}{RQ} \right) $$
https://www.youtube.com/watch?v=vrjK4gxa-48
$$ P_{(A-a)}O_2 = P_AO_2 - P_aO_2 $$
or, in room air (FiO2 of 0.21, at sea level)
$$ P_{(A-a)}O_2 = \left[ 150 - \frac{P_aCO_2}{0.8} \right] - P_aO_2 $$
Our friends at MD Calc can help with these calculations:
https://www.mdcalc.com/calc/243/a-a-o2-gradient

Altalag, A., Road, J., Wilcox, P., Aboulhosn, K. (2019). Arterial Blood Gas (ABG) Interpretation. In: Altalag, A., Road, J., Wilcox, P., Aboulhosn, K. (eds) Pulmonary Function Tests in Clinical Practice. In Clinical Practice. Springer, Cham. https://doi.org/10.1007/978-3-319-93650-5_8
