William was born in the early hours of the morning on 21 August 1765 at Buckingham House, the third child and son of King George III and Queen Charlotte. He had two elder brothers, George and Frederick, and was not expected to inherit the Crown. He was baptised in the Great Council Chamber of St James's Palace on 20 September 1765. His godparents were his paternal uncles, the Duke of Gloucester and Prince Henry (later Duke of Cumberland), and his paternal aunt, Princess Augusta, then hereditary duchess of Brunswick-Wolfenbüttel.
He spent most of his early life in Richmond and at Kew Palace, where he was educated by private tutors. At the age of thirteen, he joined the Royal Navy as a midshipman, and was present at the Battle of Cape St Vincent in 1780. His experiences in the navy seem to have been little different from those of other midshipmen, though in contrast to other sailors he was accompanied on board ships by a tutor. He did his share of the cooking and got arrested with his shipmates after a drunken brawl in Gibraltar; he was hastily released from custody after his identity became known.
He served in New York during the American War of Independence, making him the only member of the British royal family to visit America up to and through the American Revolution. While William was in America, George Washington approved a plot to kidnap him, writing: "The spirit of enterprise so conspicuous in your plan for surprising in their quarters and bringing off the Prince William Henry and Admiral Digby merits applause; and you have my authority to make the attempt in any manner, and at such a time, as your judgment may direct. I am fully persuaded, that it is unnecessary to caution you against offering insult or indignity to the persons of the Prince or Admiral..." The plot did not come to fruition; the British heard of it and assigned guards to William, who had until then walked around New York unescorted. In September 1781, William held court at the Manhattan home of Governor Robertson. In attendance were Mayor David Mathews, Admiral Digby, and General Delancey.
He became a lieutenant in 1785 and captain of HMS Pegasus the following year. In late 1786, he was stationed in the West Indies under Horatio Nelson, who wrote of William: "In his professional line, he is superior to two-thirds, I am sure, of the [Naval] list; and in attention to orders, and respect to his superior officer, I hardly know his equal." The two were great friends, and dined together almost nightly. At Nelson's wedding, William insisted on giving the bride away. He was given command of the frigate HMS Andromeda in 1788, and was promoted to rear-admiral in command of HMS Valiant the following year.
William sought to be made a duke like his elder brothers, and to receive a similar parliamentary grant, but his father was reluctant. To put pressure on him, William threatened to stand for the House of Commons for the constituency of Totnes in Devon. Appalled at the prospect of his son making his case to the voters, George III created him Duke of Clarence and St Andrews and Earl of Munster on 16 May 1789, supposedly saying: "I well know it is another vote added to the Opposition." William's political record was inconsistent and, like many politicians of the time, cannot be certainly ascribed to a single party. He allied himself publicly with the Whigs as well as his elder brothers George, Prince of Wales, and Frederick, Duke of York, who were known to be in conflict with the political positions of their father.