This line was opened in 1783 by the owners of Halbeath Colliery. It ran from the colliery which was sited about a mile to the north of the current village of Halbeath to the harbour at Inverkeithing and was single track throughout with passing loops every 550 yards. The gauge of the Halbeath Railway is not clear although it was certainly not standard gauge (the Elgin Railway was 4ft gauge and the Fordell Railway 4ft 4ins gauge). That the line was not standard gauge is apparent from the fact that when the Edinburgh & Northern made connections with the Railway in 1848 (see below) this required a third rail to be added.
In addition to coal from the Halbeath and latterly other collieries in the Townhill area (see below), Thomas notes that there was also considerable traffic from other sources, including the limestone quarry at Sunnybank, the freestone quarries at Bonnyside and Rosebank and the distillery at Boreland in Inverkeithing. Iron edge-rails were laid in 1811. It appears from photographs in Simpson & Robertson that the line also served the Inverkeithing Fire Brick and Gas Retort Works to the north of Inverkeithing (opened c.1831) and also the Inverkeithing Gas Company's gasworks off Waggon Road and south of King Street in Inverkeithing.
A branch was built in 1841 to give access to the Townhill Collieries to the east of Town Loch, just north east of Dunfermline. This line, which was known as the Townhill Tramway, was eventually extended westward to connect with the Elgin Railway which served collieries to the north west of Dunfermline. This extension appears to have taken place around 1856 when the West of Fife Mineral Railway linking Kelty to Whitemyre Junction just west of Dunfermline was opened. By that time the Edinburgh & Northern had itself been permitted to make a junction with the Townhill Tramway (the site of Townhill Junction between Dunfermline Queen Margaret and the level crossing at the former Halbeath station is still visible) and to the Halbeath Colliery. These connections were made in 1848. There was a considerable dispute over how the Edinburgh & Northern was to cross the Halbeath Railway (confirming the location of the Halbeath Colliery to the north of the current A907 and the present main line) and the Townhill Tramway slightly further west. The opposition apparently came from the Edinburgh & Perth which had acquired an interest in the Halbeath Railway. Ultimately crossings on the level were agreed. The connections are clearly visible on the 1856 map of the area. Clearly the connections to the main line network sounded a death knell for the Halbeath Railway. While the Halbeath Colliery closed in 1850, it appears that the railway's branch to Townhill, the Elgin Railway and various other connections to Inverkeithing continued to operate until 1867. Traffic from the Townhill Collieries was ultimately all routed to Charlestown, particularly after the NB takeover of the Elgin Railway in 1863.
It is clear from photographs in Simpson & Robertson that the track at the Inverkeithing end of the route remained in place after 1867 and that there was a connection made between to the NB North Queensferry/Rosyth line at what subsequently became Inverkeithing South Junction when the Forth Bridge line opened. Presumably this connection was put in when the North Queensferry line was opened on 1 November 1877. The photographs in Simpson & Robertson disclose a horse drawn coal wagon at the Inverkeithing gas works in the 1890s, a track leading to the Inverkeithing Fire Brick and Gas Retort Works to the north of Inverkeithing dated around 1895 in which the track appears to show signs of use and a picture showing the connection between the NB and the Halbeath Railway at Inverkeithing South Junction at around 1890 after the opening of the Forth Bridge line. The latter picture shows trucks standing on the track of the Halbeath Railway. These pictures raise some interesting questions. It is seems clear that the survival of the track of the Halbeath Railway in the Inverkeithing area enabled the NB to serve a range of Inverkeithing businesses (the Boreland Distillery had been a customer of the Halbeath Railway) from the 1877 when the North Queensferry branch opened. However, it is not clear whether the railway continued to operate at the Inverkeithing end between 1867 and 1877. It may be, for example, that coal shipments arrived at Inverkeithing Harbour and were delivered locally by horse drawn wagons on the Halbeath Railway. The pictures also raise the question of re-gauging. None of the pictures show a third rail so it is clear that the line had been regauged by this time. Perhaps this was done in 1877 when the link to the NB system at Inverkeithing was made.
There is no evidence that any form of crossing was provided under/over the Burntisland - Inverkeithing link line (opened 2 June 1890) built to link the Forth Bridge to the existing main line starting at Burntisland. Given the closure of the Halbeath Railway in 1867 it is unlikely a crossing would have been required so it may be presumed that the route of the Halbeath Railway was cut with the construction of the Burntisland - Inverkeithing line and the northern part of the Inverkeithing triangle. However, the photograph in Simpson & Robertson which shows the line running to the Inverkeithing Fire Brick and Gas Retort Works to the north of Inverkeithing provides tantalising evidence in this regard. The works were situated to the east of the Great North Road (now the B981), just south of Inverkeithing East Junction. The photograph is dated circa 1895. The embankment which carried the Great North Road up to the bridge on which it crossed over the NB line leading to Inverkeithing station just south of Inverkeithing Central Junction is apparent in the left centre of the photograph. Large telegraph poles and signal gantries are just visible behind the embankment. Looking directly down the route of the Halbeath Railway one sees in the middle distance what seems to be another signal gantry which carries four signals - presumably the signals which would control access to the two routes diverging from Inverkeithing East Junction on the down side. It is clear that the track of Halbeath Railway thus continued almost right up to the Inverkeithing - Burntisland line but it remains unclear if any access across the route was provided.
There is also evidence of a line running from the Fordell Railway via Hillend and Spencerfield to Inverkeithing during the 1920s. It is unclear when this line was constructed or who operated it although it seems to post date the Halbeath Railway as it is not shown on the 1856 map of the Inverkeithing area.
Some remains of the Halbeath Railway may be seen from Inverkeithing station. Looking behind the fence of the down (Edinburgh) platform at the station one can see the Keithing Burn and a small embankment on the burn's far bank which runs parallel to the platform. This embankment carried the Halbeath railway. Looking south from the down platform a road bridge carrying Boreland Road crosses the main line at Inverkeithing South Junction, the point at which the branch to Rosyth Dockyard (and also formerly North Queensferry) diverges to the left. Immediately to the left of that bridge can be seen a single arch bridge through which the line of the Halbeath railway passed. It passed in front of the row of modern flats (formerly the site of large distillery maltings) and continued via Waggon Road (obvious reason for the name!) keeping to the east side of the Keithing Burn until it reached the harbour. Inverkeithing Harbour was originally located at the mouth of the Keithing Burn with piers on both east and west banks. The large grassy area in front of Preston Crescent (to the east of the Keithing Burn) was formerly a bay. At the harbour the Halbeath railway split with a line crossing to the west side of the Keithing Burn (behind which Caldwell's Paper Mill now stands) to run along the west pier and another line continuing along the east pier.
Leaving Inverkeithing station and continuing north along the B981, the former Great North Road, shortly after the road crosses the East Coast Main Line at Inverkeithing East Junction a junction is reached with an unclassified road leading at right angles to the left. A very short distance along this road it passes through a strip of trees which marks the line of the Halbeath Railway. There was a level crossing here and indeed there is a cottage at the crossing which might well have been the crossing keeper's house. A path continues along the line of route through the strip of trees on the right although it is not possible to follow this very far as the M90 motorway cuts across the former route just a few yards further on.
Little now remains of the railway north of the M90 because of the massive house building programme going on to the east of Dunfermline at present. The line of route north of the M90 followed the Pinkerton Burn, crossing what is now the B916 to the west of Mid Duloch and continuing northwards to Calais Muir Wood. The road shown on OS Landranger 65 (1995 edition) running north from the north eastern edge of Calais Muir Wood to Halbeath is on the line of the old railway. However, the layout of this area is hardly recognizable with the mothballed Hyundai/Motorola plant to the west, the new leisure complex at Junction 3 on the M90 and the huge new housing estates at various stages of construction.
The connection with the Townhill line was made to the west of where the NB's Townhill branch diverged from the main line (the latter is still visible). The area here has been much altered with the construction and subsequent demolition of BR's Townhill Depot and the construction of out of town stores on the site. Slightly further to the northwest, from where it passed under what is now the B912, the former Townhill Tramway continues as part of National Cycle Route 1/Kingdom Cycle Route. To the east of the B912 overbridge the line of the Townhill Tramway has been filled in for some distance until close to the main line where its course is visible at the former junction.
North of the A907 the Halbeath Railway followed the route of the present unclassified road which leads over the present Fife Circle line at Halbeath level crossing. The connection between Halbeath Railway and the Edinburgh & Northern enabling the latter to access Halbeath Colliery was apparently just north of the level crossing with a spur on the east side linking the Halbeath Railway to the up line of the main line. The Halbeath Railway continued for around 3/4 mile northwards roughly along the course of the current unclassified road. Again, the landscape here is much altered. Interestingly a huge opencast mine was operated in recent years just to the east of the M90 at this point - accessing some of the coals which had formerly been part of the Halbeath Colliery.