There are several answers to this, all of which are interrelated to some degree. We can list the most important ones as follows:
1. Washington knew that as long as he kept an army alive and in the field, the rebellion could not be ended by the British.
He was defeated in battle more often than he was victorious, but each time his army survived to fight another day. The conflict became a war of attrition in which the British were worn down even in battles they won, and the cumulative effect was to exhaust them and sap them of the will to go on fighting.
This became more apparent than ever during the Southern campaign in 1780-1781, when General Nathaniel Greene, in many ways Washington's right-hand man, repeatedly engaged the British and essentially won the campaign without actually winning a single individual battle.
2. Isolated, surprise victories—especially at Trenton in December, 1776—had the effect of demoralizing the British, who were unprepared for defeat on any level.
Washington's Trenton victory also caused other European leaders to take the American cause seriously, as Frederick the Great of Prussia did in predicting at this point that the Patriots would win the war.
3. The British themselves were divided on how to manage the war and even on the overall policy pursued by the King and his administration.
The Whig Party was sympathetic to the Patriot cause, and the ambivalent situation caused the British military effort to be conflicted and unaggressive. British generals such as Howe did not wish to engage in a "total war" against a people who were perceived by many in Britain as simply trying to stand up for their rights as Englishmen. At some stages of the conflict, it may have been possible for the British to destroy Washington's army, but they did not, partly because they did not take the independence effort seriously and did not wish to make the effort to follow up their own victories with a true knock-out blow.
This was the case in the autumn of 1777 when Howe preferred, after his victory at Brandywine, merely to settle down and spend a quiet winter in Philadelphia (hosted by the wealthy Philadelphia Loyalist families) instead of pursuing Washington to his encampments first in Whitemarsh and then Valley Forge and destroying him.
4. The alliance established with the French in 1778 meant that the British were now fighting their principal European enemy and that the war had become an international conflict with naval engagements in the West Indies as well.
With the combination of Washington's and Rochambeau's armies at Yorktown and the bottling up of the outlet to the Atlantic by De Grasse's fleet, Cornwallis was forced to surrender. At that point in October, 1781, the British had been exhausted by six years of war after which they were no closer to ending the rebellion than they had been at the start of the conflict. Parliament no longer had the will to continue an effort on which they had been divided in the first place, and thus voted to begin negotiations with the aim of granting independence to the colonies—already, of course, self-declared as independent since July, 1776.
By a purely conventional military analysis, the British certainly had the advantage over the colonials. With that being stated, however, you should recognize that the Americans made use of unconventional military tactics. They knew the land better than the British did, and they made effective use of this advantage, utilizing hit and run tactics and ambushes, not always giving the British a direct confrontation.
North America in the late-eighteenth century was a very different world than North America today. There were great stretches of wilderness that the British would have had to deal with, along with very poor roads. This would have been in sharp contrast to conditions on the other side of the Atlantic, and the colonists exploited these conditions to their advantage.
Beyond this, recognize that the Americans did not fight the Revolutionary War alone. Indeed, the reason that the Battle of Saratoga was so important was that this victory convinced France to enter the war in aid of the American cause. The colonials had allies against Britain, and this support was critical in ensuring their success.
The Americans were not expected to defeat the British military in the Revolutionary War. However, the unexpected occurred, and the Americans defeated the British. There were reasons why this occurred.
The British generals made some mistakes. General Howe went to Philadelphia instead of going to Saratoga. The British planned on having three armies arrive at Saratoga, but only one army made it there. General Burgoyne also moved very slowly because he brought many unnecessary items with him.
The Americans got help from Spain and France, enemies of Great Britain, after the Americans won the Battle of Saratoga. These countries provided money and weapons. Also, some foreign soldiers came to join the American side. These soldiers also helped train the American army. The French navy helped the Americans trap the British at Yorktown. This led to the British surrender, ending the war.
The Americans had several reasons for which to fight and win. Many of the leaders of the American Revolution would likely have been killed if the Americans had lost the war. Additionally, the Americans were fighting for their freedom. These factors really motivated the Americans to fight and to win.
https://alphahistory.com/americanrevolution/why-the-americans-won-the-revolutionary-war/
https://www.history.com/topics/american-revolution/battle-of-saratoga