In 1824, Carnot proposed a cycle operating on reversibility principles. He proved that there exists an upper limit of the efficiency of this cycle and this limit is also the upper limit for any real process. The irreversibility related to the finite-time and the finite-size constraints are fundamental for the optimization of any real thermodynamic system. It has been pointed out how fundamental is the interaction between any open system and its surroundings. The meaning of the Carnot efficiency is that even in the ideal condition, when there is no dissipation, there exists something that does not allow the system to convert all the energies absorbed in work. The aim of this paper is to show why this happens, starting from a variational approach of thermodynamics.