Because of the disaffection of millions of Sanders backers during the DNC primaries and proof of election fraud in state primaries, many voters are considering writing him in if their state allows write in ballots. Could he actually win if enough voters do this? If so, how many votes or states would it take?
Short answer: It is possible for a theoretical write-in to win enough votes in a presidential election to actually win. It is not possible for Bernie Sanders in the 2016 race to win, because he has not filed the necessary paperwork to have ballot access in many states.
America has 50 states. Each state can handle ballots differently. This information is from Ballotpedia's article on ballot access.
- 9 of 50 states don't allow write-in candidates at all. These states are Nevada, New Mexico, Oklahoma, South Dakota, Missouri, Louisiana, Mississippi, South Carolina, and Hawaii. That is 54 electoral college votes that a write-in candidate cannot possibly win.
34 of 50 states allow write-in candidates, but require them to file before the election. This question is specifically about Bernie Sanders. Since he didn't file to be on the presidential ballot in these states, he is not eligible to have any electors represent him in the electoral college from these states. Each state has different deadlines for this paperwork. In Maine, this has to be done by mid-September, while in Washington it could be done in early October.
In the remaining 7 states, write-in candidates are allowed without prior registration. These states are Oregon, Iowa, Pennsylvania, New Jersey, Rhode Island, Vermont, and New Hampshire. This states have 58 total votes in the electoral college.
Since Bernie Sanders could only win electors in 7 of the 50 states, he could only possibly win 58 electoral votes. The magic number is 270 electoral votes - which this is far short of.
How Many Write-Ins Are Necessary?
Voting is a competition. There isn't a magic number of votes needed to win an election, you need to have more than your competitors. The total number of voters isn't static either: voter turnout can have a big variance across the nation and in different elections.
To use Oregon as an example: In 2012 Barack Obama won the electors from Oregon. He had about 970,000 votes in that state. A write-in candidate would need more than the highest-placing candidate on the ballot, so they would need more than 970,000. Nation-wide, a write-in candidate would need tens of millions of votes and those votes would have to be concentrated enough to carry states.
For a different sense of context, Barack Obama received approximately 65 million popular votes in 2012 and only had 51% of the popular vote. [Source: Wikipedia article on the 2012 presidential election]
If no candidate wins the majority of electoral votes, the House of Representatives will vote. The details of this process are captured in this question. The top three candidates will be on the House's "ballot". If enough Representatives voted for Bernie Sanders this way, he could still win.
Yes, he could if and only if he had help from the House of Representatives.
@indigochild's analysis that Sanders cannot get 270 electoral college votes to win the nomination outright is correct. It is possible, however unlikely, for him to get enough electoral college vote to prevent both Trump and Clinton from getting 270 electoral college votes as well. If that were to occur the House of Representatives would select the president from candidates with electoral college votes. With negative public sentiment for both major party candidates, he could possibly be selected in this situation.