How will votes be counted and when will we know who's won? Here's how the BBC will report the referendum result.
How are the votes counted?
Polls close at 22:00 and ballots will be counted in 382 counting areas. These are mostly local authorities.
The first stage will see all ballot papers - though not actual votes - counted, a process known as verification.
Any ballots which are later rejected are included in these verified ballots.
Leave and Remain votes will then be counted and any rejected ballots - where the voter's intention is not clear or the ballot is deemed to be spoiled - will be set aside.
How are results announced?
Local totals of Leave & Remain votes will be announced for each counting area at the local counts.
Local counting officers then relay their local totals to their respective regional counting officer, who will in turn announce the regional total for each of the UK's 11 government regions, and Northern Ireland.
Once every region is complete, the chief counting officer, Jenny Watson, who is chairwoman of the Electoral Commission, will announce the official referendum result from count HQ in Manchester.
Unless the result is very close, it is likely that the BBC and other broadcasters will be able to forecast the winner before this point, by analysing turnout and voting patterns.
What are the counting areas?
The counting areas are 380 local authorities in England, Scotland and Wales, plus one counting area for Northern Ireland and one for Gibraltar - the territory at the southern tip of Spain which is part of the UK.
The Channel Islands and the Isle of Man are not part of the UK and therefore not in the EU, so do not vote in the referendum.
What are 'local results' in Northern Ireland?
Although the Electoral Commission treats Northern Ireland as a single counting area, referendum ballots will actually be counted in eight locations and the local counting areas are Northern Ireland's 18 UK parliamentary constituencies.
Counting officers at these eight locations will make the 18 constituency results known to the Chief NI Counting Office in Belfast, who will in turn make these figures available to the press.
These constituency totals will be added to the BBC's results system via BBC representatives present at the Belfast count.
The Northern Ireland constituency results will be displayed on our web pages to provide local voting information. The BBC will describe these each one as a "Local result only".
The 18 constituencies do not appear in the overall tally of 382 and are not considered by the Electoral Commission as official declarations.
What is the 'winning post'?
To win the referendum one side must win 50% of valid votes cast, plus one vote or more.
However the winning side could be apparent before all votes have been counted.
After turnout from some counting areas is known, BBC analysts will be able forecast an estimated "winning post" target.
As local totals are declared, and more turnout information emerges, the target will become a calculated one, based on turnout and the electorates of the remaining undeclared counting areas.
The target may drop quite rapidly as the count progresses and more turnout figures come in from each local counting area.
How is turnout calculated?
The turnout figure is based on valid votes cast for leave and remain expressed as a percentage of the registered electorate.
So if there were 502,034 valid votes cast in Birmingham Council and an electorate of 707,819, the turnout would be: 502,034 / 707,819 x 100 = 71%
National turnout is based on the sum of valid votes so far, divided by the sum of declared electorates.
Electorate information for each counting area will be provided by the Electoral Commission once verification commences on referendum night.
What are 'rejected ballots'?
Rejected ballots are papers where the voting intention is deemed to be unclear or invalid.
Reasons a ballot can be rejected include, it:
- does not bear the official mark
- has votes for more than one choice
- has writing or marks by which the voter can be identified (except the printed ballot paper number or other unique identifying mark)
- is unmarked, or the voting intention is uncertain
When will we know the final result?
Officially, when either Leave or Remain passes the winning post by achieving 50% of ballots cast plus at least one vote.
But unless the result is very close, it is likely that BBC analysts will be able to forecast one side to have won earlier, based on turnout and voting patterns.
The final official result is announced by the chief counting officer in Manchester.
What about recounts if the result is very close?
The referendum rules do not provide for a national recount to be carried out in any circumstances.
Any request for recounts of votes in the individual counting areas will be decided by the local counting officers.
Can the final result be challenged after it has been announced?
Yes - but only by an application for judicial review, which must be made within six weeks of results being announced.
The referendum result is not legally binding. Parliament still has to pass the laws that will get Britain out of the EU, starting with the repeal of the 1972 European Communities Act.
What happens if the referendum ends in a dead heat?
This is uncharted territory.
The probability of this happening at a national level is vanishingly small, but an Electoral Commission spokesman told the Daily Telegraph that in such an event it would be a matter for parliament to decide what happened next.
What does the BBC's results graphic show?
The hemicycle graphic displays Leave and Remain totals as coloured increments as the count progresses.
The red dotted line is the 50% winning post.
The grey central bloc represents the undeclared votes and voters.
Once accurate turnout figures are known, the bloc will become smaller.