The North Berwick Branch is a short railway branch line built by the North British Railway to connect North Berwick, in East Lothian, Scotland to the East Coast Main Line  (at Drem). It was built as a tactical means of excluding competitors from the area, and when it opened in 1850 it was loss making. The later development of North Berwick as a resort and a golfing centre transformed the branch line.
 Goods train operation on the branch ceased in 1968, but the line was electrified in 1991 and now enjoys a regular interval passenger service to Edinburgh.
 The North British Railway obtained its authorising Act of Parliament in the 1844 session, to build a line from Edinburgh to Berwick (later known as Berwick-upon-Tweed). From the outset this was to be a trunk railway, connecting at Berwick with the Newcastle and Berwick Railway and onwards to the growing English railway network. A Scottish network was forming too, and the competition between the promoters of proposed lines, and the directors of authorised lines, became intense.
 The first main line was to run east from Edinburgh, where there was to be a terminal station at the North Bridge, to East Linton, Dunbar and Berwick. The geographical position of North Berwick, and its lack of commercial significance at the time, meant that it was not to be on the main line, although it was a Royal Burgh with a population of 1,600.
 However, in the frenzied atmosphere of competition, the Directors became alarmed at the possibility of rival railways entering the area, and at this early date, abstracting traffic. A line from Dalkeith to East Linton was being proposed, and it was suspected that the railway financier George Hudson, earlier an ally, was behind a move to make this part of the main route from Edinburgh in place of their own (as yet unbuilt) line.
 To head off this threat, the Directors of the North British Railway set about getting authorisation for branch lines to several places adjacent to their main line, to pre-empt the rival incursion. In addition, North Berwick was judged to have the potential for the construction of superior residential districts for Edinburgh merchants, who might travel daily to their place of business, by train. A special shareholders' meeting held on 9 February 1846 approved four Bills to go to Parliament for branch lines; one of these swept up branches to Duns, North Berwick, Tranent and Cockenzie; estimated capital required was £170,000. On 16 June 1846 the Royal Assent was granted to a North British Railway Act for the branch lines, including one to North Berwick from Drem. At North Berwick the line was to extend through the town a far as the harbour.
 Contracts for construction were let in early 1847, but financial problems for the North British began to set in. Although the main line had been built, the Company had committed to building the Edinburgh and Hawick Railway, a line criticised as being nearly as long as the main line, and running through relatively sparsely populated terrain; and a number of other expensive schemes were straining the NBR's finances. The North Berwick branch was now to be completed only when money became available.
 The Town Council of North Berwick were demanding a high price for the land required for the continuation of the line through the town, and the NBR reviewed its plan to extend to the harbour, eventually (in November 1848) deciding to abandon that part of the branch line plan. In fact the land acquisition for the shortened line as actually built cost £18,949 compared with £7,083 estimated.
 Remarkably, the branch was being constructed as a double line; "a mistake" according to Thomas. In early 1849 it was reported that the earthworks for the line were substantially complete but that the permanent way was only partly laid, and the decision was taken to lift one of the (incomplete) tracks so as to finish a single line. At this stage it emerged that the remaining earthwork was a deep cutting approaching North Berwick, and in August 1849 the Directors ordered that the cutting should be formed for a single line only.
 In order to generate some income, the Board decided to open the line as far as Williamston, The location was just short of the cutting. The Board of Trade inspection, required for passenger train opening, took place on 4 August and the line opened as far as Williamston on 13 August 1849. A temporary wooden platform was provided there, and horse conveyances took passengers on to North Berwick; there were four trains daily (except Sundays).
 Completion of the line took longer than expected, and it was not until 17 June 1850 that the line opened throughout, with an intermediate station at Dirleton; Williamston was closed on the same day. The line joined the main line some distance east of Drem station; the station itself had two platforms, with no separate bay for the branch trains that terminated there. The construction of the line had cost £116,766. At some later date a separate line was provided for the branch to run independently to the station. The signalling system on the single line branch was by telegraph order.
 Traffic on the branch was not heavy, and the line made a loss. The Directors had promoted numerous lines at the time with the object of keeping other railways out of the area. This was the so-called "protection" policy, but a later shareholders' committee expressed regret that the Directors had undertaken the building of the line. Efforts were made to encourage the high class residential traffic that had been originally contemplated, by offering very attractive season ticket rates to the first occupiers of new houses near the line.
 Cost savings were attempted when a vehicle built for horse traction on the Leith branch of the Dalkeith line was tried on the North Berwick line. A pathway in the centre of the track had to be made for the horse, at a cost of £65. The passenger service was reduced to two return trips daily by the horse-drawn vehicle (referred to as "the Dandy"), and the new arrangement started on 1 November 1856, as the winter traffic was light. The goods traffic on the branch was handled by the main line pick-up goods train, which now travelled up and down the branch as well; this disrupted and extended onward goods transits on the main line.
 John Scott, an Edinburgh solicitor raised a case against the North British Railway that he had been induced to take up residence in North Berwick and that the discontinuance of the steam-operated service was prejudicial to his rights. He claimed £5,000 in damages from the NBR. His case was eventually thrown out, but protracted legal proceedings provided much entertainment for readers of the newspapers of the area.
 The horse operated service evidently did not achieve the savings the company had hoped for, and from 1 May 1857 a steam operated service of four daily mixed trains was resumed. The Dandy car was never used on the branch again, and about 1859 it was sold to the Carlisle and Silloth Bay Railway who used it on the Silloth branch. It is now preserved at the National Railway Museum in York.
 About 1860 the train staff and ticket system of signalling control was introduced on the branch.
 On the North Berwick branch subsequently a small 0-4-2 well-tank locomotive, no 20, was the regular motive power. From about 1875 golf became of considerable popularity and began to bring traffic to the line, and in the season regular through trains from Edinburgh were put on. A ticket platform was erected just short of North Berwick station.
 North Berwick became a popular resort, and many well-to-do families took houses there for the summer season; the breadwinner of the family travelled daily to a place of business in Edinburgh or Glasgow and the family remained in the resort. In the late Victorian and Edwardian era, golf also became increasingly popular, and the practice of travelling some distance for a game became established. The station facilities at North Berwick were upgraded in March 1894.
 The North British Railway put on a train service named The Lothian Coast Express. It ran from 12 June 1912  to August of that year. It ran in the afternoon from Glasgow to Dunbar, via Edinburgh Waverley. Ross states that the train ran through Waverley without stopping there, the only scheduled passenger train to do so. The train conveyed a Gullane portion, detached at Longniddry and a North Berwick portion, detached at Drem, and it conveyed a refreshment car. The return service left Dunbar in the morning and picked up the North Berwick and Gullane portions at Drem and Longniddry, and it served breakfast. The train was said to have been the first British named train to carry a headboard with the train name. The Lothian Coast Express was suspended during World War I but it was reinstated in 1919.
 In 1923 the North British Railway was "grouped" under the Railways Act 1921, becoming a constituent of the new London and North Eastern Railway (LNER).
 From 1923 road competition started; at first it was limited but by the 1930s it was a serious alternative to the railway branch line.
 From 1924 a through sleeping car ran from London to North Berwick, detached from the main (Edinburgh) train at Drem. It ran in the summer season only, and in later years it was reduced to Friday northwards and Sunday southwards. A single first class sleeping car vehicle was used. The service ceased in 1939.
 In an attempt to reduce costs, the LNER introduced Sentinel steam railcars on the North Berwick branch. Trials were carried out in 1928 and from 1930 the railcars regularly appeared on the branch. They were not an unqualified success, but they continued operating part of the passenger service, running through from North Berwick to Edinburgh, until the late 1930s.
 The Lothian Coast Express continued running, but changing business patterns meant that fewer business people wished to use the train, and 1934 was the last season in which it ran.
 Goods traffic declined substantially in the period to 1939 as road transport became the normal means of transport for agricultural produce. The passenger service on the branch was substantially reduced during World War II and not much enhanced after 1945.
 Dirleton station was always isolated, and its use by a few passengers declined too, and on 1 February 1954 the station was closed to passengers.
 The LNER had been nationalised in 1948, and British Railways Scottish Region was the organisational unit in control. The branch was loss-making, and in attempt to revive it, British Railways implemented some modernisation schemes in the Edinburgh area, and diesel multiple unit trains were introduced on the branch passenger services from 23 July 1956, when a demonstration run took place, and from 3 February 1958 a recast diesel operated service ran on a regular interval basis, with all trains running to Edinburgh Waverley and some continuing to Corstorphine. Some steam working continued for the time being. Meanwhile, the goods business had collapsed, and it was discontinued from 1 January 1968, and the line was reduced to a single line without siding or loop facilities.
 In 1968 British Railways proposed complete closure of the branch on the ground that it was loss-making, but the Minister of Transport refused consent, and the line continued in use. However further economies had to be made, and this included a substantial reduction in the train service pattern; this was introduced from 4 January 1970.
 In January 1985 the traditional station buildings were demolished, having become unsafe, and a new simple shelter was erected. The single platform was shortened by 50 yards.
 In October 1990 the Scottish section of the East Coast Main Line was electrified, and shortly before the day of switching on the power, agreement was reached between British Rail and Lothian Regional Council to share the cost of electrifying the North Berwick branch, at a cost of £1.3 million. The overhead line equipment was energised on 18 May 1991. Finding rolling stock for the service was not easy, and after some research five units of class 305/2, built in 1960 and employed up until then in the London commuter area, were obtained. Internal layout changes were made and through corridor connections fitted.
 The full electric train service started operation on 8 July 1991. Although the old electric multiple unit trains suffered reliability problems, and lacked air conditioning, their high-density seating layout abolished the overcrowding that had been experienced at peak times, and they proved surprisingly popular.
 Leaving Drem Junction, the line falls at 1 in 110 for nearly half a mile, then becoming level. Next it climbs at 1 in 93 for a mile, then falling at 1 in 2348 for 1½ miles, finally falling at 1 in 66 for a mile to North Berwick.
 The branch is four miles and seven chains in length.
 The North Berwick branch has been served by a variety of rolling stock over its life. Steam locomotives were typically tank engines, North British Railway 4-4-0T, 0-4-4T and 4-4-2T successively being the norm. By the end of regular steam passenger service on the branch in 1958, LNER Class V1/V3 2-6-2T engines were the usual power. Despite there being no turntable, tender engines were also used on both passenger and goods traffic, mainly 4-4-0s and 0-6-0s. Excursion traffic very occasionally brought larger engines such as K3 Class 2-6-0s. LNER steam railcars were tried in the late 1920s and '30s, with limited success. Clayton Type 1 diesel locomotives operated the branch goods service in its final years, but subsequently visits by diesel locomotive have been confined to occasional engineering trains.
 Early diesel multiple units (DMUs) used on the line from 1958 onwards were Class 100 and Class 101. Subsequently, many different types of DMU appeared on the line, including Class 104, Class 105, Class 107, Class 108 and Class 120. In 1987 new Class 150 Sprinter DMUs took over some services.
 Upon electrification by British Rail in 1991, five thirty-year-old 305 electric multiple units (EMUs) were refurbished for the line, having been made redundant from London Liverpool Street suburban services. In their later years these trains became unreliable and deputisation by diesel units (including equally elderly Class 117s) was not uncommon. Prior to privatisation, it was not unknown for InterCity 125 diesel-electric units to operate to North Berwick if no other train was available.
 In the early 2000s, most services were operated using five Class 322 4-car EMUs. These trains were built in 1990 for use on Stansted Express services, but were displaced from these services by 2001 when they were leased to ScotRail to allow withdrawal of the elderly Class 305s. They were occasionally assisted by Class 318s especially during the half-hourly services on Saturdays. Their lease expired in mid-2004 and the 322s returned to England, prompting a search for suitable replacement stock. No modern EMUs were available at the time, and the line reverted to locomotive haulage for a time, using Class 90 electric locomotives hired from EWS and former Virgin Trains West Coast Mark 3 coaches, with each set incorporating a DVT to allow push-pull operation.
 In mid-2005 the Class 322 units became available again, refurbished for permanent use by First ScotRail. Apart from the Class 322s, diesel units of Classes 156, 158 and 170 also operated some services, mainly on Saturdays when there were not enough EMUs to maintain a half-hour frequency throughout the day.
 In June 2011, Class 380s began operating the North Berwick line, phasing out all Class 322s which were all returned to England. They were cascaded onto the Wakefield Line with Northern Rail. When the Saturday daytime services to Dunbar by ScotRail were introduced in December 2012, the Class 170 Turbostar regularly took on these services. Following the Borders Railway construction in September 2015, the Class 158 Express Sprinter took over the Dunbar services. In the December 2017 timetable, the Class 380 took over services to Dunbar on Saturdays and subsequently replaced by Class 385s in the December 2018 timetable. Class 170s previously ran to North Berwick during the peak hour, particularly whenever ScotRail lack EMUs based in Edinburgh. However this no longer takes place, with EMU’s running exclusively on the line.
 In September 2018, ScotRail services on the North Berwick Line have started using the new Class 385 units. Services are formed of either three or six coaches (either one or two 3-car units).
 As of December 2023, Class 385s now operate most services over the Class 380s, with both operating a mix of North Berwick and Dunbar services.
 This line consists of the North Berwick Branch between North Berwick and Drem and the East Coast Main Line between Drem and Edinburgh Waverley. The section between Drem and Edinburgh Waverley shares the track with London North Eastern Railway's London Kings Cross - Edinburgh Waverley service. It consists of all or part of the following Network Rail routes:
 Passenger services are operated by ScotRail. The line is electrified at 25 kV AC overhead.
 The North Berwick Line is open to passenger traffic served by Scottish Government-owned ScotRail.
 Services run between North Berwick and Edinburgh Waverley (with one morning peak-time service continuing to Haymarket) and is generally hourly between 6am and 10pm, with a slightly more frequent service at peak time. An hourly service also runs on weekends.
 ScotRail services to Dunbar have been incorporated into the same timetable (Table 216) since May 2010. Initially services did not typically stop at intermediate stations. However, since May 2011 all ScotRail services have called at Musselburgh and since December 2023 also at Wallyford and the re-opened East Linton. These services run two hourly during Mondays-Saturdays with an additional late night service.