When atoms undergo fusion, energy is released. This is due to an increase in the binding energy between the particles that make up the nucleus. Binding energy is a negative energy; in the sense that it requires an investment of energy to split the constituent particles of a nucleus.
The binding energy arises from a nuclear force. This acts between 2 neutrons, 2 protons and between a neutron and a proton. The nuclear force keeps the nucleus from breaking apart due to the repulsive forces between the positively charged protons. The measurement of the mass of nuclei has revealed that the mass of the constituent protons and neutrons is more than the mass of the nucleus. The decrease in mass is converted to energy which is given off.
Two atoms undergo fusion if the binding energy of the resultant atom is more than that of the atoms which fuse. This is the case with atoms of light elements undergo fusion, for example helium has a higher binding energy than hydrogen. It is seen that the difference in the binding energy continues to decrease as the atoms undergoing fusion become heavier. Iron has the highest binding energy. Beyond iron there is no increase in the binding energy, this makes fusion reactions come to a stop at iron.
After iron, energy is released when the atoms are split into smaller atoms. This is the principle behind the generation of energy by nuclear fission. For example uranium atoms release energy not when they combine to form a larger atom but the other way around.