William Bayly, son of a farmer, was appointed as assistant to the Astronomer Royal, N. Maskelyne, at the Royal Greenwich Observatory in November 1766, mainly because of his proficiency in mathematics. During the next few years he acquired good skills as an observer. On Maskelyne's recommendation the Royal Society of London sent him to Nordkapp, in the north of Norway, to observe the transit of Venus on 3 June 1769. He was accompanied by Jeremiah Dixon*. Their observations were published in the society's Philosophical Transactions. Bayly left his post at Greenwich in March 1771.
The next year he and William Wales* were engaged by the Board of Longitude to accompany Captain James Cook on his second expedition around the world, mainly to make astronomical observations for navigational purposes. Though Bayly was by this time a competent astronomer he had less education and abilities than Wales. None the less he designed and made a portable observatory for use on the expedition, which Wales described as "undoubtedly one of the most convenient portable observatories that has yet been made" (Beaglehole, Vol. 2, p. 722n). Bayly travelled on the Adventure, commanded by Captain T. Furneaux, while Wales was stationed with Cook on the Discovery. The expedition circumnavigated the world and among others reached the ice along the shores of Antarctica. On their way from England to New Zealand they visited the Cape from 30 October to 23 November 1772. Bayly and Wales went ashore to test and calibrate their chronometers and check the longitude of the Cape. On the return journey they again visited the Cape from 21 March to 21 April 1775. They occupied the site in Concordia Gardens (behind the present Roman Catholic cathedral in Cape Town) where C. Mason* and J. Dixon had observed the transit of Venus in 1761. A traverse was performed to link this site to the house in Strand Street where N. De la Caille* had established his temporary observatory in 1751. Their observations during the expedition were edited by Wales and published in 1777 as The original astronomical observations made in the course of a voyage towards the South Pole and round the world, in his Majesty's ships the Resolution and Adventure in the years 1772, 1773, 1774, and 1775, with Bayly as the second author. He kept a short journal during the voyage, covering the period June 1773 to July 1774.
Both men accompanied Captain Cook on his third expedition, from 1776 to 1780. Bayly first travelled on the Discovery, but was transferred to the Resolution in August 1779, some time after Cook's death. The expedition visited the Cape from 8 October to 30 November 1776 and on the return journey anchored in Simon's Bay from 11 April to 9 May 1780. After their return Bayly prepared the observations made by Captain Cook, Lieutenant King and himself for the press. They were published as The original astronomical observations made in the course of a voyage to the northern Pacific Ocean... (London, 1782) under the names of Cook, King and Bayly.
In February 1785 Bayly was appointed headmaster of the Royal Naval Academy at Portsmouth, where he remained until his retirement on pension in 1807. His last years were marked by the tragic death of his wife and seven children, all but one of them from consumption (tuberculosis).