Hamilton was born on 13 December 1730 (or 12 January 1731) in either London or at Park Place, Berkshire, the fourth son of Lord Archibald Hamilton, governor of Jamaica, seventh son of William Douglas-Hamilton, Earl of Selkirk, by the 3rd Duchess of Hamilton, and Lady Jane Hamilton, daughter of James Hamilton, 6th Earl of Abercorn. His mother was a favourite, and possibly a mistress, of the Prince of Wales and William grew up with his son George III, who would call him his "foster brother". At age nine, he went to Westminster School, where he made lifelong friends of Frederick Hervey and David Murray. Hamilton used to say that he was born with an ancient name and a thousand pounds; as a younger son he would have to make his own way in life. So, six weeks after his sixteenth birthday, he was commissioned into the 3rd Foot Guards as an ensign. He spent some time with the regiment in the Netherlands, and advanced to lieutenant in 1753. In September 1757, he was present as aide-de-camp to General Henry Seymour Conway at the abortive attack on Rochefort. The following year he left the Army, after having married Catherine Barlow, the daughter of Hugh Barlow, Member of Parliament for Pembroke Boroughs. The couple shared a love of music, and the marriage, which lasted until Catherine's death on 25 August 1782, was a happy one. There were no children. When Catherine's father died in 1763, she inherited his estates in Wales and these provided the Hamiltons with a steady income.