The St Andrews Railway was an independent railway company founded in 1851 to build a railway branch line from the University town of St Andrews, in Fife, Scotland, to the nearby main line railway. It opened in 1852. When the Tay Rail Bridge opened in 1878 residential travel to Dundee was encouraged.
The railway was engineered as a low-cost line by Thomas Bouch and the company suffered adversely from that in later years, and sold their line to the larger North British Railway in 1877.
The line was successful until road transport competition began to abstract traffic, and when the Tay Road Bridge opened in 1966, 40% of the line's passenger carryings were lost immediately. Decline continued and the line closed completely in 1969.
The town of St Andrews is ancient. The University of St. Andrews was founded in 1411, but there was relatively little industry in the town, linen weaving being the chief occupation., and agriculture; there was a paper mill at Guard Bridge.
The engineer Robert Stevenson was commissioned to survey a railway route crossing Fife in 1819; the route he selected was similar to the later Edinburgh, Perth and Dundee Railway, running some distance from St Andrews. However this would have been a long distance route and the steam locomotives of the day were not practicable, and the scheme was dropped.
In 1835 John Geddes surveyed a line from Burntisland to Ladybank, forking there and running respectively to Perth and the location that became Tayport. This scheme too failed to develop into a proposal, but a revised survey of 1840 gained support as the economic situation improved, and as railways elsewhere had demonstrated that longer distances could be handles by railways. In 1840 the Edinburgh and Northern Railway was proposed, following this route, and the proposal led to an authorising Act of Parliament on 31 July 1845.
There were some late changes to the proposed route, but the Edinburgh and Northern Railway's line opened on 20 September 1847 between Burntisland and Cupar by way of Kirkcaldy and Ladybank. The Company had changed its name on 27 July 1847 to the Edinburgh Perth and Dundee Railway (EP&DR) on merging with its partner railway at Granton. It extended to Leuchars, not far from St Andrews on 17 May 1848. The Edinburgh and Northern was an immediate success, although the Forth had to be crossed by ferry from Granton: at this stage there was no question of bridging the Forth or the lower Tay.