What is Article 50?

Britain inches closer to Brexit and Theresa May has hinted she will trigger Article 50 to leave the European Union in the coming months. So what exactly is Article 50 and how does it work?