Thermodynamics serves as a universal means for studying physical systems from an energy perspective. In recent years, with the establishment of the field of stochastic and quantum thermodynamics, the ideas of thermodynamics have been generalized to small fluctuating systems. Independently developed in mathematics and statistics, the optimal transport theory concerns the means by which one can optimally transport a source distribution to a target distribution, deriving a useful metric between probability distributions, called the Wasserstein distance. Despite their seemingly unrelated nature, an intimate connection between these fields has been unveiled in the context of continuous-state Langevin dynamics, providing several important implications for nonequilibrium systems. In this study, we elucidate an analogous connection for discrete cases by developing a thermodynamic framework for discrete optimal transport. We first introduce a novel quantity called dynamical state mobility, which significantly improves the thermodynamic uncertainty relation and provides insights into the precision of currents in nonequilibrium Markov jump processes. We then derive variational formulas that connect the discrete Wasserstein distances to stochastic and quantum thermodynamics of discrete Markovian dynamics described by master equations. Specifically, we rigorously prove that the Wasserstein distance equals the minimum product of irreversible entropy production and dynamical state mobility over all admissible Markovian dynamics. These formulas not only unify the relationship between thermodynamics and the optimal transport theory for discrete and continuous cases, but also generalize it to the quantum case. In addition, we demonstrate that the obtained variational formulas lead to remarkable applications in stochastic and quantum thermodynamics, such as stringent thermodynamic speed limits and the finite-time Landauer principle. These bounds are tight and can be saturated for arbitrary temperatures, even in the zero-temperature limit. Notably, the finite-time Landauer principle can explain finite dissipation even at extremely low temperatures, which cannot be explained by the conventional Landauer principle.1 MoreReceived 26 July 2022Revised 1 December 2022Accepted 13 December 2022DOI:https://doi.org/10.1103/PhysRevX.13.011013Published by the American Physical Society under the terms of the Creative Commons Attribution 4.0 International license. Further distribution of this work must maintain attribution to the author(s) and the published article’s title, journal citation, and DOI.Published by the American Physical SocietyPhysics Subject Headings (PhySH)Research AreasEntropy productionNonequilibrium & irreversible thermodynamicsNonequilibrium statistical mechanicsQuantum thermodynamicsStochastic processesStochastic thermodynamicsThermodynamics of computationTechniquesGraph theoryStatistical PhysicsInterdisciplinary PhysicsGeneral Physics