In glycolysis, two molecules of ATP are consumed initially in converting glucose to fructose 1, 6-bisphosphate. Two triose phosphate molecules are formed from one glucose molecule. Four molecules of ATP are produced at substrate level phosphorylation. Therefore, net gain of ATP is 2ATP$\times$2$-$2ATP = 2.