Stirling was born in Cloag, Perthshire, Scotland, the third of eight children. He inherited his father's interest in engineering, but studied divinity and became a minister of the Church of Scotland in 1816. He soon became concerned about the danger the workers in his parish faced from steam engines, which frequently exploded because of the poor quality of the iron boilerplate available at the time, and decided to improve the design of an existing air engine in the hope that it would provide a safer alternative. Within a year he invented a regenerator, which he called the Heat Economiser, a device for improving the efficiency of an air engine. He obtained a patent for the economiser, and an air engine incorporating it, in 1817. Stirling's engine could not explode, because it worked at a lower pressure, and could not cause steam burns. In 1818 he built the first practical version of his engine, used to pump water from a quarry.
In 1819 Stirling married Jean Rankin, who would bear him seven children.
Later, in Kilmarnock, he collaborated with another inventor, Thomas Morton, who provided workshop facilities for Stirling's research. Both men were interested in astronomy, and having learnt from Morton how to grind lenses, Stirling invented several optical instruments.
Robert's brother James, also an engineer, built a large air engine at his Dundee Foundry Company.
In a letter of 1876, Robert Stirling acknowledged the importance of Henry Bessemer's new invention - the Bessemer process for the manufacture of steel - which made steam engines safer and threatened to make the air engine obsolete. However, he also expressed a hope that the new steel would improve the performance of air engines.
Stirling died in Galston, Ayrshire.
The theoretical basis of Stirling's engine, the Stirling cycle, would not be understood for another forty [?] years until the work of Sadi Carnot (1796 - 1832). Carnot produced a general theory of heat engines, the Carnot cycle, of which the Stirling cycle is a special case.