The majority of ATP synthesis takes place within the mitochondrial matrix during cellular respiration, with each molecule of glucose oxidized creating around molecules.
Energy is liberated and used to pump protons out of the matrix as electrons flow down the chain, resulting in a gradient.
Protons flow back into the matrix and are converted to ATP by an enzyme called ATP synthase.