A Brexit vote is not legally binding, it could be totally ignored by UK government. There are a few ways that it could theoretically be blocked or overturned. However, as the BBC notes, "it would be seen as political suicide to go against the will of the people as expressed in a referendum."
The EU has to be notified of its withdrawal. Article 50 of the Treaty on European Union establishes the procedures for a member state to withdraw from the EU. Once Britain invokes Article 50, it will have a two-year window in which to negotiate a new treaty to replace the terms of EU membership.
A Brexit vote, however, does not represent that formal notification. That notification could take place within days. EU member countries meet for a summit that is scheduled for June 28 to 29.