At first, it may seem very simply and obvious: the flange keeps the wheel on the track, right?
Nope, that’s not the answer!
To understand why, let’s first get some background on how train wheels are made:
The primary take away from the above video is that train wheels are big and come together with a joined axle — that is, they don’t have a differential. If you don’t know what a differential is, or want to be impressed by an awesome video from 1937, take a look-see as this:
That still doesn’t explain what keeps a train on the track though. If you haven’t been able to figure it out yet, Feynman will explain:
…and that’s called rail adhesion.