The only legal way for a Brexit – or for any member state to withdraw from the European Union – is by triggering an obscure and controversial clause in the Lisbon Treaty: article 50. It gives the departing country two years to negotiate the terms of its withdrawal and has never been used before. Tom Clark explains how it works