The idea of railway guns appears to have been first suggested in the 1860s by a Mr Anderson, who published a pamphlet in the United Kingdom titled National Defence in which he proposed a plan of ironclad railway carriages.
A Russian, Lebedev, claimed to have first invented the idea in 1860 when he is reported to have mounted a mortar on a railway car. The first railway gun used in combat was a banded 32-pounder Brooke naval rifle mounted on a flat car and shielded by a sloping casemate of railroad iron. On 29 June 1862, Robert E. Lee had the gun pushed by a locomotive over the Richmond and York River line (later part of the Southern Railway) and used at the Battle of Savage's Station to interfere with General George McClellan's plans for siege operations against Richmond during the Union advance up the peninsula. France also used improvised railways guns during the Siege of Paris in 1870 and the United Kingdom mounted a few 4.7 in (120 mm) guns on railway cars which saw action during the Siege and Relief of Ladysmith during the Second Boer War. A 9.2 inch gun was taken from the Cape Town coast defenses and mounted on a rail car to support the British assault on Boer defences at Belfast, north-east of Johannesburg, but the battle ended before it could get into action.
In France, Lt. Col Peigné is often credited with designing the first railway gun in 1883. Commandant Mougin is credited with putting guns on railcars in 1870. The French arms maker, Schneider offered a number of models in the late 1880s and produced a 120 mm (4.7 in) gun intended for coastal defense, selling some to the Danish government in the 1890s.
The outbreak of the First World War caught the French with a shortage of heavy field artillery. In compensation, large numbers of large static coastal defense guns and naval guns were moved to the front, but these were typically unsuitable for field use and required some kind of mounting. The railway gun provided the obvious solution. By 1916, both sides were deploying railway guns.
Baldwin Locomotive Works delivered five trains for the United States Navy during April and May 1918. Each train transported and supported a 14 in (356 mm) naval rifle mounted on a rail carriage with four 6-wheel bogies. These guns were the Mk 4 14"/50 caliber guns used on New Mexico and Tennessee class battleships. Baldwin constructed six similar gun carriages and two of an improved Mk II type designed to permit firing the gun at all elevation angles without transferring weight to a separate foundation. These eight guns were completed too late to see combat
The Second World War saw the final use of the railway gun, with the massive 80 cm (31 in) Schwerer Gustav gun, the largest artillery piece to be used in combat, deployed by Germany.
Both Germany and Great Britain employed railway-mounted guns that were capable of firing across the English Channel between the areas around Dover and Calais. Germany employed a number of 40 cm guns. Britain employed three 13.5-inch (342.9 mm) railway mounted guns on the East Kent Light Railway, located around Lydden and Shepherdswell. These were known as Gladiator, Sceneshifter and Piecemaker. 9.2 inch Mark 13 guns were located near Canterbury and Hythe; an 18 inch Howitzer, Boche Buster, sited on the Elham Valley Railway, between Bridge and Lyminge; and 12 inch howitzers, Mk 3 and 5, located around Guston.
The rise of the aeroplane effectively ended the usefulness of the railway gun. Similar to stationary battleships, they were massive, expensive, and, in the correct conditions, easily destroyed from the air.