Under the terms of Article 50, Britain will cease to be an EU member in March 2019.
But EU negotiators warn it could take two years just to settle the divorce terms; agreeing on a new relationship for the U.K. and the EU could take years longer. If the rest of the EU agrees, the two-year negotiating period can be extended, leaving Britain in the EU for a while longer. Or, the two sides could agree on a transitional period.
There's also a chance Britain could walk away early without a deal if it thinks the talks are going nowhere.