During the first few decades of the 19th century, the ironworks at Cyfarthfa (and neighbouring Dowlais) continued to expand, and at their height were the most productive ironworks in the world: 50,000 tons of rails left just one ironworks in 1844, for the railways across Russia to Siberia. With the growing industry in Merthyr, several railway companies established routes linking the works with ports and other parts of Britain. They included the Brecon and Merthyr Railway, Vale of Neath Railway, Taff Vale Railway and Great Western Railway. They often shared routes to allow access to coal mines and ironworks through rugged country, which presented great engineering challenges. According to David Williams, in 1804, the world's first railway steam locomotive, "The Iron Horse", developed by the Cornish engineer Richard Trevithick, pulled 10 tons of iron with passengers on the new Merthyr Tramroad from Penydarren to Quakers Yard. He also claims that this was the "first 'railway' and the work of George Stephenson was merely an improvement upon it". A replica of this locomotive is in the National Waterfront Museum in Swansea. The tramway passed through what is arguably the oldest railway tunnel in the world, part of which can be seen alongside Pentrebach Road at the lower end of the town. The demand for iron was also fuelled by the Royal Navy, which needed cannon for its ships, and later by the railways. In 1802, Admiral Lord Nelson visited Merthyr to witness cannon being made.
