Here is a timetable of what could happen if the UK votes to leave the European Union, based on information from the Cabinet Office and the European Council:
:: June 24 2016: Referendum result shows that a majority of the UK has voted to leave the European Union. An EU summit, already scheduled for June 23/24, could respond immediately to the result.
:: Early July 2016: Emergency legislation is passed by the UK Parliament, before the summer break begins, to start the process of withdrawal. This would include invoking Article 50 of the Lisbon Treaty, which is necessary to formally declare the UK's intention to leave the EU.
:: July 2016: An emergency EU summit could be held to agree the timetable for negotiating the UK's withdrawal and to approve the invoking of Article 50.
:: October 20/21 2016: An EU summit, already scheduled for these dates, could formalise the timetable for UK withdrawal, along with plans for any treaty changes.
:: From autumn 2016 to 2018: Talks continue to agree the terms of the UK's withdrawal. These would be led by the European Commission. Under Article 50, negotiations must be complete with two years.
:: By summer 2018: Negotiations on withdrawal would need to be concluded. Member states and the EU Parliament would then vote on the terms of the UK's application to withdraw. Some 20 of the 27 countries need to vote in favour for the application to pass; a majority of MEPs also need to agree.
:: By the end of 2018: the UK would leave the EU.
:: 2018-20: The negotiation period could be extended, but only with the unanimous support of member states. If there is not unanimous agreement, the UK will be ejected from the EU automatically when the initial two-year negotiating period elapses. If the negotiations do continue, treaty changes may have to be passed by the parliaments of the remaining 27 countries before the UK's withdrawal becomes official.
:: Between 2018 and 2020: David Cameron is expected to stand down as Conservative leader and prime minister.
:: May 2020: date of the next UK general election. Talks for the UK to leave the EU could still be under way.