Rankine developed a complete theory of the steam engine and indeed of all heat engines. His manuals of engineering science and practice were used for many decades after their publication in the 1850s and 1860s. He published several hundred papers and notes on science and engineering topics, from 1840 onwards, and his interests were extremely varied, including, in his youth, botany, music theory and number theory, and, in his mature years, most major branches of science, mathematics and engineering.
He was born in Edinburgh to Lt David Rankin (sic), a civil engineer from a military background, who later worked on the Edinburgh to Dalkeith Railway (locally known as the Innocent Railway). His mother was Barbara Grahame, of a prominent legal and banking family.
His father moved around Scotland on various projects and the family moved with him. William was initially educated at home but he later attended Ayr Academy (1828–29) and then the High School of Glasgow (1830). Around 1830 the family moved to Edinburgh when the father got a post as Manager of the Edinburgh to Dalkeith Railway. The family then lived at 2 Arniston Place.
In 1836, Rankine began to study a spectrum of scientific topics at the University of Edinburgh, including natural history under Robert Jameson and natural philosophy under James David Forbes. Under Forbes he was awarded prizes for essays on methods of physical inquiry and on the undulatory (or wave) theory of light. During vacations, he assisted his father who, from 1830, was manager and, later, effective treasurer and engineer of the Edinburgh and Dalkeith Railway which brought coal into the growing city. He left the University of Edinburgh in 1838 without a degree (which was not then unusual) and, perhaps because of straitened family finances, became an apprentice to Sir John Benjamin Macneill, who was at the time surveyor to the Irish Railway Commission. During his pupilage he developed a technique, later known as Rankine's method, for laying out railway curves, fully exploiting the theodolite and making a substantial improvement in accuracy and productivity over existing methods. In fact, the technique was simultaneously in use by other engineers – and in the 1860s there was a minor dispute about Rankine's priority.
The year 1842 also marked Rankine's first attempt to reduce the phenomena of heat to a mathematical form but he was frustrated by his lack of experimental data. At the time of Queen Victoria's visit to Scotland, later that year, he organised a large bonfire situated on Arthur's Seat, constructed with radiating air passages under the fuel. The bonfire served as a beacon to initiate a chain of other bonfires across Scotland.
Undaunted, he returned to his youthful fascination with the mechanics of the heat engine. Though his theory of circulating streams of elastic vortices whose volumes spontaneously adapted to their environment sounds fanciful to scientists formed on a modern account, by 1849, he had succeeded in finding the relationship between saturated vapour pressure and temperature. The following year, he used his theory to establish relationships between the temperature, pressure and density of gases, and expressions for the latent heat of evaporation of a liquid. He accurately predicted the surprising fact that the apparent specific heat of saturated steam would be negative.
Emboldened by his success, in 1851 he set out to calculate the efficiency of heat engines and used his theory as a basis to deduce the principle, that the maximum efficiency possible for any heat engine is a function only of the two temperatures between which it operates. Though a similar result had already been derived by Rudolf Clausius and William Thomson, Rankine claimed that his result rested upon his hypothesis of molecular vortices alone, rather than upon Carnot's theory or some other additional assumption. The work marked the first step on Rankine's journey to develop a more complete theory of heat.
Energetics offered Rankine an alternative, and rather more mainstream, approach, to his science and, from the mid-1850s, he made rather less use of his molecular vortices. Yet he still claimed that Maxwell's work on electromagnetics was effectively an extension of his model. And, in 1864, he contended that the microscopic theories of heat proposed by Clausius and James Clerk Maxwell, based on linear atomic motion, were inadequate. It was only in 1869 that Rankine admitted the success of these rival theories. By that time, his own model of the atom had become almost identical with that of Thomson.
Rankine was one of the first engineers to recognise that fatigue failures of railway axles was caused by the initiation and growth of brittle cracks. In the early 1840s he examined many broken axles, especially after the Versailles train crash of 1842 when a locomotive axle suddenly fractured and led to the death of over 50 passengers. He showed that the axles had failed by progressive growth of a brittle crack from a shoulder or other stress concentration source on the shaft, such as a keyway. He was supported by similar direct analysis of failed axles by Joseph Glynn, where the axles failed by slow growth of a brittle crack in a process now known as metal fatigue. It was likely that the front axle of one of the locomotives involved in the Versailles train crash failed in a similar way. Rankine presented his conclusions in a paper delivered to the Institution of Civil Engineers. His work was ignored however, by many engineers who persisted in believing that stress could cause "re-crystallisation" of the metal, a myth which has persisted even to recent times. The theory of recrystallisation was quite wrong, and inhibited worthwhile research until the work of William Fairbairn a few years later, which showed the weakening effect of repeated flexure on large beams. Nevertheless, fatigue remained a serious and poorly understood phenomenon, and was the root cause of many accidents on the railways and elsewhere. It is still a serious problem, but at least is much better understood today, and so can be prevented by careful design.
Rankine was instrumental in the formation of the forerunner of Glasgow University Officer Training Corps, the 2nd Lanarkshire Rifle Volunteer Corps at Glasgow University in July 1859, becoming Major in 1860 after it was formed into the first company of the 2nd Battalion, 1st Lanarkshire Rifle Volunteer Corps; he served until 1864, when he resigned due to pressure of work – much of it associated with Naval Architecture.