Let's say I write-in "John Smith" on a ballot, how does the election board know which John Smith I voted for? Even if I write in a well known politician like let's say Paul Ryan, there must be more than 1 Paul Ryan in the US. Does the election board simply assume it's Paul Ryan the speaker of the house, and not Paul Ryan my college roommate?
Candidates are Registered
Of the 41 states that allow write-in candidates, 34 (about 80%) of them require the candidate to file as a write-in candidate (source: Ballotpedia). When you vote, the name you write will be traced to the names of registered write-in candidates. If the name doesn't match, your vote doesn't go anywhere.
Candidates are Not Registered
So what about the 7 states where candidates don't have to pre-file? I couldn't find a source online, so I called the Iowa Secretary of State's office as a case study.
According to their office, write-in candidates are only considered if more than 5% of a certain race in a certain county has a write-in. In other cases, they are basically too small too be counted. They do often have write-in candidates win elections in small races, and in those cases identifying the winner is relatively easy: the population of possible candidates is small and the candidate will have been actively campaigning.
They could not tell me how this is handled in larger races (like Presidential races, gubernatorial, etc.) because it has never happened and is unlikely to ever happen (by their estimate).
It really depends on which state you are voting. According to the linked ABC News article on Election 2016: What You Need to Know About Write-Ins, states don't have the same policy towards write-in candidates. For example:
Only eight states -– Alabama, Iowa, North Dakota, New Jersey, Oregon, Pennsylvania, Rhode Island and Vermont -– tally write-ins without requiring candidates to file paperwork, the NASS says, and even the least restrictive states have some disqualifying criteria.
In Alabama, for example, write-in candidates must be: 1. qualified to hold the office, 2. able to reach a threshold number of votes, 3. “nonfictional,” and 4. alive, in order to be officially tallied.
It doesn't matter which Paul Ryan you will write-in because they will never be elected and there has been no president in the US history who was elected by write-in votes.
Regardless, write-in votes, which generally make up less than 1 percent of all the votes cast in a presidential election, probably won’t come close to electing a president. (Emphasis added)