WASHINGTON (AP) — How will you know who won Tuesday's elections? County and state governments count the votes and eventually certify the results. But that can take weeks.

Americans are used to learning most of their winners on election night, whether the news comes from television, radio, a newspaper, a website or a tweet. That's possible because of the election network built by The Associated Press, a not-for-profit news cooperative.

The AP will deploy more than 5,000 people Tuesday to provide vote-count results and to call races in national, state and local contests and key ballot measures in the midterm election.

Here's how it's done:

___

BEFORE ELECTION DAY

More than 30 states have some form of advance voting, by mail or in person. More than a third of voters in 2012 cast their ballots that way.

State and county elections officials don't release the results of advance voting until after polls close. But to reflect those votes, the voter surveys known as "exit polls" start by phone in some states more than a week before Election Day.

___

EARLY AND OFTEN

When polling places open Tuesday morning, exit poll interviewers will be standing outside some voting sites. They'll ask a random sample of people leaving the voting booths throughout the day to fill out confidential questionnaires about their votes and opinions on issues. The exit polls are run by the National Election Pool, made up of the major television networks and the AP.

___

WHEN POLLS CLOSE

As early vote returns start coming in, AP workers stationed in nearly every U.S. county will collect the tallies from elections officials and phone them in to AP tabulation centers, where data-entry clerks will work through the night. Also, the AP gathers results from state and county websites, and receives direct electronic feeds of vote results from some states.

After several checks to ensure accuracy, AP sends the returns to members and customers, and ultimately the public. They are frequently updated.

___

A RUSH OF NUMBERS

For some statewide races that are landslides, the exit polls provide enough information for the AP to determine who won right after polls close.

The AP and the networks analyze the exit polls independently and make their own calls, but all agree to hold off on calling any race until voting in that race is over. That's why poll closing times can bring a flurry of winners.

___

MAKING THE CALLS

Experienced AP journalists in each state analyze partial vote returns as they come in.

When is a race ready to call? When AP analysts are convinced that the trailing candidate can't catch up, given the number of votes still outstanding and the voting history of the locations that have yet to report totals.

Race callers use their on-the-ground knowledge of each state's politics and detailed data on its voting history and demographics. In some statewide races, such as contests for the governorship or a U.S. Senate seat, exit polls add more information to help the AP determine the winner. The race callers also get help from analysts in the AP's Washington bureau.

A "decision desk" in Washington has final signoff on high-profile calls.

In 2012, the AP called 4,653 contested races with an accuracy rate of 99.9 percent. It expects to count 4,590 contested elections Tuesday.

Despite these efforts, you can expect some races to remain too close to call with the returns available Tuesday night.