Inelasticity, the fraction of a neutrino's energy transferred to hadrons, is a quantity of interest in the study of astrophysical and atmospheric neutrino interactions at multi-TeV energies with IceCube. In this work, a sample of contained neutrino interactions in IceCube is obtained from five years of data and classified as 2650 tracks and 965 cascades. Tracks arise predominantly from charged-current ν μ interactions, and we demonstrate that we can reconstruct their energy and inelasticity. The inelasticity distribution is found to be consistent with the calculation of Cooper-Sarkar et al. across the energy range from ∼1 to ∼100 TeV. Along with cascades from neutrinos of all flavors, we also perform a fit over the energy, zenith angle, and inelasticity distribution to characterize the flux of astrophysical and atmospheric neutrinos. The energy spectrum of diffuse astrophysical neutrinos is described well by a power law in both track and cascade samples, and a best-fit index γ ¼ 2.62 AE 0.07 is found in the energy range from 3.5 TeV to 2.6 PeV. Limits are set on the astrophysical flavor composition and are compatible with a ratio of ð 1 3 ∶ 1 3 ∶ 1 3 Þ ⊕. Exploiting the distinct inelasticity distribution of ν μ andν μ interactions, the atmospheric ν μ toν μ flux ratio in the energy range from 770 GeV to 21 TeV is found to be 0.77 þ0.44 −0.25 times the calculation by Honda et al. Lastly, the inelasticity distribution is also sensitive to neutrino charged-current charm production. The data are consistent with a leading-order calculation, with zero charm production excluded at 91% confidence level. Future analyses of inelasticity distributions may probe new physics that affects neutrino interactions both in and beyond the Standard Model.