Trains stay on the tracks thanks to a clever design feature called "flanges." These are slightly extended rims on the wheels that slot into the rails, guiding the train and preventing derailments.