According to the second law of thermodynamics, energy flows in the direction of increasing randomness. This randomness is quantified as entropy, a universal value that always increases due to the inescapable dissipation of energy.
Each time energy is transferred or transformed in an open system, some of this energy is lost in the form of random thermal vibrations called heat. Starting with a fixed amount of useful energy, the total amount of energy available to do work decreases until eventually all of this energy has dissipated as heat. Even if this resulting heat energy is trapped in a system, there is no way to restore it to its former form of useful energy without expending more than the original amount of energy.
As a result, energy always flows from more complex forms to less complex ones and from more concentrated forms to less concentrated ones. The flow of thermal energy from a higher temperature to a lower one or the flow of electrical energy from a higher voltage potential to a lower one are both illustrations of this. Even chemical reactions are subject to this law of thermodynamics, in which the total bond energy of the reactants of a spontaneous reaction is always less than the bond energy of the products.