Egypt began to gain independence from Britain during World War I when British efforts to occupy and control Egypt began to wane. Ultimately, when political pressure in Egypt led to a revolt, Britain declared Egypt independent. This occurred in January of 1922.

Egypt gained independence from Britain after a sequence of events:
This is a brief history of how Egypt gained independence from Britain. Lets look at some of these events.
The first World War had much to do with putting an end to British occupation in what was then referred to as the Kingdom of Egypt, which wasn’t officially formed and named until 1922.
With the British rule losing steam and the British failing to enforce the enactment of their appointed king of Egypt, Hussein Kamil, the uprising of Muslim resistance groups (especially the Muslim Brotherhood) began to effectively cause problems and erode any British influence within the Egyptian territory.
By the time World War I was in full swing, virtually shutting down the Suez Canal, British energies and forces were already starting to be redirected for the war effort. By 1922, most of the power behind the British influence, both military and culturally, had either shifted or left Egypt altogether. The official regime change in Egyptian territory would follow shortly thereafter.
In fact, following World War I, a party called the Wafd Party led a nationalist movement which attempted to establish independence. When the British exiled the leader of the movement, Saad Zaghlul, this led to a revolt which caused Britain to declare Egypt independent on January 2, 1922.
The Egyptian government also took advantage of the remnants of the amenities that were instituted during the period of British rule, including the railroad system. The Egyptian government implemented lanes of commerce through the Suez Canal that was previously controlled by the British after their invasion in 1882.
Although this is how Egypt gained independence from Britain, this is not to say that the evidence of British presence was completely obliterated, with the declaration of independence. As a matter of fact, many British officials remained in Egypt, and the British also maintained military forces in Egypt, which remained in the country until the early 1950s. These British individuals and the British presence remained even after the formation of the official Kingdom of Egypt in 1922, shortly after the biggest pullout of British troops.
In all, the British influence in Egypt lasted for a period of roughly 85 years, with the power shifting back to Egyptian dominance in the early 1920s.