One key objective of the population health sciences is to understand why one social group has different levels of health and well-being compared with another. Whereas several methods have been developed in economics, sociology, demography, and epidemiology to answer these types of questions, a recent method introduced by Jackson and VanderWeele (2018) provided an update to decompositions by anchoring them within causal inference theory. In this paper, we demonstrate how to implement the causal decomposition using Monte Carlo integration and the parametric g-formula. Causal decomposition can help to identify the sources of differences across populations and provide researchers with a way to move beyond estimating inequalities to explaining them and determining what can be done to reduce health disparities. Our implementation approach can easily and flexibly be applied for different types of outcome and explanatory variables without having to derive decomposition equations. We describe the concepts of the approach and the practical steps and considerations needed to implement it. We then walk through a worked example in which we investigate the contribution of smoking to sex differences in mortality in South Korea. For this example, we provide both pseudocode and R code using our package, cfdecomp. Ultimately, we outline how to implement a very general decomposition algorithm that is grounded in counterfactual theory but still easy to apply to a wide range of situations.