Due to their important role in space weather, coronal mass ejections or CMEs have been thoroughly studied in order to forecast their speed and transit time from the Sun to the Earth. We present a thermodynamic analytical model that describes the dynamics of CMEs. The thermodynamic approach has some advantages with respect to the hydrodynamic approach. First, it deals with the energy involved, which is a scalar quantity. Second, one may calculate the work done by the different forces separately and sum all contributions to determine the changes in speed, which simplifies the problem and allows us to obtain fully rigorous results. Our model considers the drag force, which dominates the dynamics of CMEs and the solar gravitational force, which has a much smaller effect, but it is, still, relevant enough to be considered. We derive an explicit analytical expression for the speed of CMEs in terms of its most relevant parameters and obtain an analytical expression for the CME temperature. The model is tested with a CME observed at three different heliocentric distances with three different spacecraft (SOHO, ACE, and Ulysses); also, with a set of 11 CMEs observed with the SOHO, Wind, and ACE spacecraft and, finally, with two events observed with the STEREO spacecraft. In all cases, we have a consistent agreement between the theoretical and the observed speeds and transit times. Additionally, for the set of 11 events, we estimate their temperatures at their departure position from their temperatures measured near the orbit of the Earth.