Mary Fairfax Somerville was born in Jedburgh, Scotland, a daughter of Vice-Admiral William George Fairfax of the Royal Navy and his wife Margaret Charters. She grew up in Burntisland, Fife, without much supervision or early education and was sent at age 10 to a boarding school for girls at Musselburgh. There she learned to read and write, and perform simple arithmetic. She persuaded her brother's tutor to teach her mathematics, although she had to study in secret because it was believed to be inappropriate and harmful for girls. She also learned Latin, Greek, and astronomy on her own initiative. In 1804, at age 24, she married her distant cousin, Captain Samuel Greig, a British diplomat and naval officer, with whom she had two children. After her husband's death three years later, she went back to Scotland and used her inheritance to acquire a small library and openly pursue her intellectual interests. In 1812, she married another cousin, Dr. William Somerville, a naval surgeon, with whom she had four children and lived in London. He shared many of her interests and encouraged and helped her in the study of math and science. She attended lectures at the Royal Institution and met many prominent scientists and intellectuals. In 1825, she began carrying out experiments on magnetism. The following year, she presented her paper, "The Magnetic Properties of the Violet Rays of the Solar Spectrum" to The Royal Society, which won her the respect of her peers as a scientist and writer. She was then asked by Lord Brougham to translate Le Mécanique Céleste of Pierre-Simon Laplace into English, which she published in 1831 under the title The Mechanism of the Heavens. It was adopted as a textbook by Oxford University and made her famous. She was elected a member of the Royal Astronomical Society and several other learned societies. Her other major works were On the Connexion of the Physical Sciences (1834), Physical Geography (1848), and Molecular and Microscopic Science (1869), published when she was nearly 90 years old. Her discussion of a hypothetical planet perturbing Uranus, in the sixth edition of On the Connexion, led John Couch Adams to the discovery of Neptune.
In 1838, she and her husband went to Italy, where she spent much of the rest of her life. In 1869, she was awarded the Patron's Medal of the Royal Geographical Society, and was made a member of the American Philosophical Society. Her literary friends included Maria Edgeworth, Margaret Holford, and Joanna Baillie. Her autobiography, Personal Recollections, was published by her daughter a year after her death. Somerville College, Oxford, was named in her honor.