According to the chemiosmotic theory, energy is utilized in order to synthesize atp within the mitochondria. This energy comes from the movement of ions (hydrogen ions) across a semipermeable membrane. This happens during the cellular respiration or photosynthesis (plants).
Hydrogen ions move across a semipermeable membrane because of the proton gradient and the movements occurs from the area with high proton concentration to an area of lower proton concentration. So, the formed electrochemical concentration gradient of protons can be used to make ATP.