As railways developed a need arose to solve the problem of trains moving up steeper sections of the rail route. The first attempts at using toothed rack rails were made in 1811 by John Blenkinsop, who built a track of cast iron rails with side rack. In 1812, Matthew Murray designed a special steam locomotive to move on such a track.
In 1848 a short section of cast iron rack rails was laid on the route of the Madison & Indianapolis Railway. But the first real rack-and-pinion railway, called the Mount Washington Cog Railway, was built in New England in 1866 – 1896 by Sylvester Marsh. In Europe, Switzerland was the first country to introduce this type of traction in 1869 – 1871. It was Vitznau-Rigi-Bahn running on land with up to a 38‰ slope. In 1891 the steam cog railway Manitou & Pikes Peak Railway reached the then record elevation – 4300.7 m AMSL. This railway still exists and currently uses diesel traction. The first electrification of a cog railway took place in Switzerland: in 1897 – Gornergrat-Bahn followed by Jungfraubahn in 1898.
At the turn of the 19th century numerous cog routes were built, in particular in the mountainous Switzerland, but also in the USA, the Beirut-Damascus line and the Trans-Andean Railway. Silesia had cog railway in the Owl Mountains, but in the 1930s the route was closed. In the 20th century many lines of this type were liquidated or replaced by suspended railways. At present, a normal gauge cog railway operates e.g. in the Czech part of the Krkonoše Mountains (the Giant Mountains), narrow-gauge – in the Slovakian part of the Tatra Mountains, while the highest number of such railways can be found in Switzerland.