The process for a member country to leave the EU is covered by Article 50 of the Treaty on European Union, as amended by the EU’s Lisbon Treaty.
Reference: The Lisbon Treaty – Article 50
Article 50 states
1. Any Member State may decide to withdraw from the Union in accordance with its own constitutional requirements.
2. A Member State which decides to withdraw shall notify the European Council of its intention. In the light of the guidelines provided by the European Council, the Union shall negotiate and conclude an agreement with that State, setting out the arrangements for its withdrawal, taking account of the framework for its future relationship with the Union. That agreement shall be negotiated in accordance with Article 218(3) of the Treaty on the Functioning of the European Union. It shall be concluded on behalf of the Union by the Council, acting by a qualified majority, after obtaining the consent of the European Parliament.
3. The Treaties shall cease to apply to the State in question from the date of entry into force of the withdrawal agreement or, failing that, two years after the notification referred to in paragraph 2, unless the European Council, in agreement with the Member State concerned, unanimously decides to extend this period.
4. For the purposes of paragraphs 2 and 3, the member of the European Council or of the Council representing the withdrawing Member State shall not participate in the discussions of the European Council or Council or in decisions concerning it.
A qualified majority shall be defined in accordance with Article 238(3)(b) of the Treaty on the Functioning of the European Union.
5. If a State which has withdrawn from the Union asks to rejoin, its request shall be subject to the procedure referred to in Article 49.
Process for withdrawing from the EU
The UK government has produced a document which outlines the actual process for withdrawing from the European Union. The document was presented to Parliament by the Secretary of State for Foreign and Commonwealth Affairs.
update: 27th June 2016
I also noticed some posts from the UK Constitutional Law Association which discuss various legal aspects of the withdrawal process:
update: 29th June 2016
Richard Ekins: The Legitimacy of the Brexit Referendum
update: 08 July 2016
The legal consequences under international and EU Law – a collection of blog posts, papers prepared by the UK government, legal advice issued by leading lawyers, journal articles, and book chapters. Its purpose is to collect together legal analysis of the consequences of the Brexit under international law and EU law. Provided by the Oxford Public International Law
update: 14 July 2016
The future of the United Kingdom in Europe: Exit scenarios and their implications on trade relations.
This memorandum is a research paper prepared on a pro bono basis by students at the Graduate Institute of
International and Development Studies (IHEID) in Geneva. It is a pedagogical exercise to train students in the
practice of international trade and investment law, not professional legal advice. As a result, this memorandum
cannot in any way bind, or lead to any form of liability or responsibility for its authors, the supervisor of the IHEID
Trade and Investment Law Clinic or the IHEID