He was born on 13 June 1831 in Edinburgh, and educated at Edinburgh and Cambridge. As a 15-year-old schoolboy he invented a new way of drawing certain oval curves, and this was published by the Royal Society of Edinburgh. He was second wrangler at Cambridge.

He was professor at Aberdeen in 1856, King's College London in 1860, and Cambridge 1871. There he organized the Cavendish Laboratory. He died on 5 November 1879.

Other fields he contributed to were colour vision, the kinetic theory of gases, and the stability of Saturn's rings, for which last he was awarded the Adams prize.