During glycolysis, two molecules of ATP are consumed during double phosphorylation of glucose to form fructose 1,6 biphosphate. In return four molecules of ATP are formed during conversion of 1,3-biphosphoglycerate to 3-phosphoglycerate and phosphoenolpyruvate to pyruvate. Two molecules of NADH are formed at the end of oxidation of glyceraldehyde 3-phosphate to 1,3-biphopshoglycerate. Each NADH molecule produces 3 ATP molecules.
Hence, total number of ATP molecules formed = 4-2+6 = 8