William Rae was born in Dumfries-shire in 1786, the son of Matthew Rae of Park End Annandale, Dumfries-shire. He was educated at Loch Maben and Dumfries and afterwards graduated M.D. at Edinburgh University.
In 1804 he entered the medical service of the East India Company and in the following year was transferred as Assistant Surgeon to the Royal Navy. His appointment as Assistant Surgeon Royal Navy dated 29 March 1805.
He served as Assistant Surgeon in the Culloden under Sir Edward Pellew. He was twenty-one years old, when in the Fox, he took part in the destruction of the Dutch ships at Gressie and Sourabaya in 1807 and 1808. Subsequently when the squadron was becalmed in the Bay of Bengal, he contrived an apparatus for distilling water.
He was appointed Surgeon, Royal Navy 29 March 1808 
When attached to the Leyden in 1812 - 13 he was very successful in his treatment of the troops suffering from yellow fever at Cartagena and Gibraltar, and received the thanks of the commander-in-chief and the medical board. 
He married his first wife Mary, daughter of Robert Bell in 1814.
William Rae was employed as Surgeon Superintendent on five convict ship voyages to Australia:
William Rae received a warrant of appointment as Surgeon Superintendent to the Eliza on 19th June 1822. He kept a Medical Journal from 19th June 1822 to 26 November 1822. In December he embarked in Sydney on the Castle Forbes for Hobart. (possibly continued to England on this vessel)
His next appointment as Surgeon Superintendent was to Isabella in 1823. The Isabella departed Cork in August 1823 and arrived in Port Jackson on 16 December 1823. William Rae kept a Medical Journal from 14th July 1823 to 24th December 1823. He was planning to leave the colony at the earliest opportunity in January 1824.
Bermuda Station 1824
In 1824 he was appointed to the Bermuda station. Here at St. George's Bermuda, he married his second wife Margaret, in June 1825. Margaret was the daughter of Robert Lee, Assistant Deputy Commissary General at Bermuda. She was born at Prince Edward Island, Canada in 1800.
Marquis of Huntley 1826
He was appointed Surgeon Superintendent to the convict ship Marquis of Huntley. The Marquis of Huntley departed Sheerness on 16 May 1826 and arrived in Port Jackson 13 September 1826. He embarked on the Fairfield for the return voyage (direct) in October 1826.
Prince Regent 1827
On his next appointment, Prince Regent convict ship, he departed London on 11 June 1827 and arrived Port Jackson on 27 September 1827. He returned to England on the Elizabeth in November 1827. Surgeon James McTernan returned on the same vessel.
Marquis of Hastings 1828
His last appointment to a convict ship was to the Marquis of Hastings. The Marquis of Hastings departed Portsmouth on 30 June 1828 and arrived in Port Jackson on 12 October 1828.
Melville Hospital Chatham 1829
He was forty-two years old at this last appointment to the Marquis of Hastings, however his career was far from over. In 1829 he was appointed Surgeon to the Melville Hospital at Chatham
In 1838 he was called on as a witness at the trial of several soldiers who had been accused of murder of mariners at Chatham. William Rae, then head surgeon of the Melville Hospital performed the post mortem examination on one of the men who had been bludgeoned to death. 
He was appointed Deputy Inspector 22 August 1840
Inspector of Hospitals and Fleets
He was appointed Inspector of Hospitals and Fleets 17 January 1849. He was Medical Inspector stationed at the Royal Hospital at Plymouth in 1849 
William Rae resided at East Stonehouse, Devon in 1851. He is aged 63 and gives his employment as Naval Officer, Inspector of Hospitals and Fleets. His wife Margaret is 38 years of age. His sister-in-law, Elizabeth Gregory age 40, a widow lived with them and also Jane Lee age 24 also a sister-in-law. They employed two servants.
The entry from the British Medical Directory 1853 gives the following information - William Rae, Royal Naval Hospital, Plymouth - L.R.C.P 1839. Lond; F.R.C.S. (Nom)1843; M.R.C.S.E. 1811; Inspector of Hospitals and Fleets and Inspector of Royal Naval Hospital Plymouth. Contributor of a 'Description of a Fracture Apparatus, with engraving' published in The Lancet.
In 1855 he was present when the First Lord of the Admiralty held his fourth levee of the season at the Admiralty, Whitehall. 
William Rae was created C.B. in 1855.. He was Knighted in 1858....The Queen was this day, 11 June, pleased to confer the honour of knighthood upon William Rae, Esq., M.D., companion of the most honourable Military Order of the Bath, and Inspector of Hospital and Fleets. 
In 1861 William and Margaret resided at North Walk Barnstaple. Their sister-in-law Mary, a spinster age 35 lived with them and they have two servants.
He is listed in the Medical Register 1865. - Residence Trafalgar Lawn, Barnstaple, Devonshire.
In 1871 they resided at Hornby Lodge with a sister-in-law and two servants.
He died aged 87 on 8 April 1873 - Sir William Rae K.C.B., Inspector-General of Hospitals and Fleets, and Justice of the Peace for the counties of Dumfries-shire and Devon, died this morning (the morning of the 8th) at his residence, Hornby Lodge, Newton, Devon aged 87. His wife was his sole heir. 
Dame Margaret Rae died at Hornby Lodge on 11 June 1892