G. H. Hardy was born in Cranleigh, Surrey, England, into a teaching family. His father was Bursar and Art Master at Cranleigh School; his mother had been a senior mistress at Lincoln Training College for teachers. Both parents were mathematically inclined. Hardy was extremely shy as a child, and was socially awkward, cold and eccentric throughout his life.
During his school years he was top of his class in most subjects, and won many prizes and awards but hated having to receive them in front of the entire school. He was uncomfortable being introduced to new people, and could not bear to look at his own reflection in a mirror. It is said that, when staying in hotels, he would cover all the mirrors with towels.
Hardy's own natural affinity for mathematics was perceptible at an early age. After schooling at Cranleigh, Hardy was awarded a scholarship to Winchester College for his mathematical work. In 1896 he entered Trinity College, Cambridge. While at university, Hardy joined the Cambridge Apostles, an elite, intellectual secret society.
From 1906 onward he held the position of a lecturer where teaching six hours per week left him time for research. In 1919 he left Cambridge to take the Savilian Chair of Geometry (and thus become a Fellow of New College) at Oxford in the aftermath of the Bertrand Russell affair during World War I. Hardy spent the academic year 1928-1929 at Princeton in an academic exchange with Oswald Veblen, who spent the year at Oxford.
Hardy is credited with reforming British mathematics by bringing rigour into it. British mathematicians had remained largely in the tradition of applied mathematics. Hardy aggressively promoted his conception of pure mathematics, in particular against the hydrodynamics which was an important part of Cambridge mathematics.
Hardy preferred his work to be considered pure mathematics , perhaps because of his detestation of war and the military uses to which mathematics had been applied.
Socially, Hardy was associated with the Bloomsbury group and the Cambridge Apostles; G. E. Moore, Bertrand Russell and J. M. Keynes were friends. He was an avid cricket fan. Maynard Keynes observed that if Hardy had read the stock exchange for half an hour every day with as much interest and attention as he did the day's cricket scores, he would have become a rich man.
He was at times politically involved, if not an activist. He took part in the Union of Democratic Control during World War I, and For Intellectual Liberty in the late 1930s.
Hardy was an atheist. He was possibly a "non-practising" homosexual. Apart from close friendships, he had a few platonic relationships with young men who shared his sensibilities, and often his love of cricket. A mutual interest in cricket led him to befriend the young C. P. Snow. Hardy was a lifelong bachelor and in his final years he was cared for by his sister.