We analytically calculate the neutrino conversion probability Pμe in the presence of sterile neutrinos, with exact dependence on Δm412 and with matter effects explicitly included. Using perturbative expansion in small parameters, the terms involving the small mixing angles θ24 and θ34 can be separated out, with θ34 dependence only arising due to matter effects. We express Pμe in terms of the quantities of the form sin(x)/x, which helps in elucidating its dependence on matter effects and a wide range of Δm412 values. Our analytic expressions allow us to predict the effects of the sign of Δm412 at a long baseline experiment like DUNE. We numerically calculate the sensitivity of DUNE to the sterile mass ordering and find that this sensitivity can be significant in the range ∣Δm412∣∼(10−4−10−2) eV2, for either mass ordering of active neutrinos. The dependence of this sensitivity on the value of Δm412 for all mass ordering combinations can be explained by investigating the resonance-like terms appearing due to the interplay between the sterile sector and matter effects.