It's the identification number. All steam locomotives were numbered, and many of them also named. The locomotive used in the Harry Potter films was one of the GWR (Great Western Railway) “Hall” class : to be precise, it was “Olton Hall”, a preserved locomotive which was - and still is - numbered 5972.