The process takes place at a biological membrane. In prokaryotes this is the plasma membrane, and in eukaryotes it is the inner of the two mitochondrial membranes. NADH and FADH2, electron carrier molecules that were "loaded" during the citric acid cycle, are used in an intricate mechanism (involving NADH-Q reductase, cytochrome c oxidase, and cytochrome reductase) to pump H+ across the membrane against a proton gradient.
A large protein complex called ATP synthase is embedded in that membrane and enables protons to pass through in both directions; it generates ATP when the proton moves with (down) the gradient, and it costs ATP to pump a proton against (up) the gradient. Because protons have already been pumped into the intermembrane space against the gradient, they now can flow back into the mitochondrial matrix via the ATP synthase, generating ATP in the process. The reaction is:
Each NADH molecule contributes enough proton motive force to generate 3 ATP. Each FADH2 molecule is worth 2 ATP. All together, the 10 NADH and 2 FADH2 molecules contributed through oxidation of glucose (glycolysis, conversion of pyruvate to acetyl-CoA, and the Krebs cycle) account for 34 of the 38 total ATP energy carrier molecules. It is worth noting that these ATP values are maximums, in reality each NADH molecule contributes between 2 and 3 ATP, while each FADH2 contributes a maximum of 2 ATP.
Several highly reactive, transient oxygen derivatives can be formed during this process: