The two-compartment model is generally used in pharmacokinetics to illustrate the distribution and excretion of drugs. In this study, we evaluated the distribution patterns of morphine and fentanyl by using a two-compartment model. Using numeric analysis techniques, non-linear ordinary differential equations were used to mathematically analyse drug distribution, transition, and concentration in the body compartments. Math Works, Inc., MATLAB, version 2023a, a programming tool, was used to characterise the impact of initial concentration and rate constants on the kinetics of the drug. For a definite therapeutic concentration of morphine and fentanyl in blood, pharmacokinetic characteristics were plotted. The study results showed the time taken by morphine and fentanyl to reach a target concentration in the blood that is sufficient to generate the preferred therapeutic effects. The mathematical models comparing morphine and fentanyl pharmacokinetics showed that fentanyl reached the target therapeutic concentration 125 minutes earlier than morphine and was metabolised and removed from the body more rapidly (44 minutes earlier than morphine). These comparative mathematical models on morphine and fentanyl enable the determination of drug dosages and understanding of drug efficacy that facilitates optimising dosing regimens. The right choice between them can be made based on the time to reach the target therapeutic concentration in the blood, elimination time, severity of pain, and patient characteristics.