The LNER D40 class is a type of 4-4-0 steam locomotive inherited from the GNSR. It consisted of GNSR class V (introduced in 1899 by William Pickersgill) and GNSR class F (introduced in 1920 by T. E. Heywood). The two classes were similar, but the class F was superheated.
The class F locomotives were the only ones to be named by the GNSR, all other classes being numbered only. The class originally comprised eight locomotives, six built by the North British Locomotive Company in Glasgow in 1920, the remaining two by GNSR at Inverurie Works in 1921.
All 21 GNSR locomotives passed to the LNER in 1923. The LNER classed them all as D40 irrespective of whether they were fitted with superheaters (class F) or not (class V). The LNER initially renumbered them by adding 6800 to their GNSR number. In 1946 they completely renumbered all their locomotives and the D40 class became 2260–2261, 2265–2272, 2262–2264 (former class V) and 2273–2280 (former class F). The first locomotive was withdrawn in 1947.
Eighteen of the 21 locomotives passed into British Railways ownership in 1948 (eleven former class V, and seven former class F). BR renumbered them by adding 60000 to their 1946 LNER number. The last locomotive of the D40 class was 62277 Gordon Highlander and it was withdrawn in 1958 from Kittybrewster Depot, Aberdeen. Number 62277 was preserved and renumbered as 49, as an example of the superheated version.