How come the H and He don't just form a layer on top of our Nitrogen atmosphere? Why do they achieve escape velocity when they go into space?
Thermal loss. The molecules in a gas have certain kinetic energy distribution. Highest energy H and He atoms reach escape velocity in the upper part of the atmosphere.
Earth's magnetic field protects it from solar winds so Earth is not losing significant amount of any heavier atoms or molecules.
Earth loses few kilograms of hydrogen and tens of grams helium per second to space.