According to folk music historian Alan Lomax as documented in his book Folk Song USA, the Midnight Special was a real train: the Southern Pacific Golden Gate Limited. A traditional folk song, Leadbelly popularized it upon his release from Sugar Land prison in Texas, where he could hear the Midnight Special come through. In the song, the light of the train gives the inmates hope - if it shines on them they take it as a sign they will soon go free.
Lyrics appearing in the song were first recorded in print by Howard Odum in 1905. The first printed reference to the song itself was in a 1923 issue of Adventure magazine. In 1927 Carl Sandburg published two different versions of "Midnight Special" in his The American Songbag.
The song was first commercially recorded on the OKeh label in 1926 as "Pistol Pete's Midnight Special" by Dave "Pistol Pete" Cutrell. In 1934 Huddie "Lead Belly" Ledbetter recorded a version of the song at Angola Prison for John and Alan Lomax, who mistakenly attributed it to him as the author. Ledbetter recorded at least three versions of the song, one with the Golden Gate Quartet, a gospel group.
Lead Belly, Big Bill Broonzy, Sonny Terry & Brownie McGhee, Odetta, Les Paul, The Kingston Trio, Pete Seeger, Peter, Paul and Mary, The Beatles, Burl Ives, Cisco Houston, Lonnie Donegan, Eric Clapton, and Creedence Clearwater Revival, among others, have recorded the song.
I probably learned it from Pete Seeger long ago.