Last night, Bernie Sanders pulled off a stunning upset in Michigan that almost no one expected — after all, he had been trailing by more than 20 points in much of the polling mere days before.

Why were the polls so wrong?

Here's one factor that helps explain what happened: Far more young people turned out to vote in Michigan's Democratic primary than most experts had assumed beforehand, according to Matt Grossmann, director of the Institute for Public Policy and Social Research at Michigan State University.

"Clearly, there was a breakdown in the models we used," said Steve Mitchell, one of the many pollsters who projected Clinton up by more than 20 points in Michigan. "It looks like there were a lot more young voters than we thought, and they voted in stronger numbers for Bernie Sanders."

A particularly dramatic example: One poll that put Hillary Clinton up by 28 points in the race expected voters ages 18 to 39 to make up only 8.9 percent of the electorate.

It turned out that 21 percent of Michigan's primary electorate was ages 18 to 29, according to exit polling cited by Grossman. Voters ages 30 to 44 accounted for another 25 percent of the vote share.

Sanders won the youth vote by an 81-19 margin. In other words, this demographic — the one most favorable to him — ended up being a greater share of the electorate by about four times what had been expected.

But that's not the only reasons polls were so off

There were at least two other major factors for Sanders's stronger-than-expected performance in Michigan.

Sanders also had a surprising ability to close the gap among black voters in Michigan. Mitchell, the pollster, said his firm projected Clinton would win African Americans by a 50-point margin — similar to margins in other states.

But according to initial exit polls, he said, Clinton ended up winning black voters in Michigan by something closer to 35 points. That's a good sign for Sanders's competitiveness in many of the delegate-rich states that lie ahead, like Ohio and Illinois, and it also partially explains why polls were so off.

Another big blind spot in the polling was its handling of independent voters. Michigan primary voters don't need to be registered Democrats to vote, and several of the polls projected that they'd only account for about 10 percent of the primary electorate.

In fact, independents — who broke for Sanders by a 71-28 margin — made up closer to 28 percent of the electorate, according to NBC News's exit polling.

Of course, everyone and their mother can come up with a pet theory for why Sanders was able to move the needle so dramatically.

Many have cited Sanders's debate performance in Flint on Sunday. Others have pointed to Clinton's misleading attack on Sanders's auto bailout position, Sanders's message on free trade, and even the idea that some Democratic voters "crossed over" to vote Republican on the assumption that Clinton is guaranteed to win the primary.

"I think when Sanders gets a cultivated state he can do pretty well," added Kyle Kondik of the University of Virginia's Center for Politics. "He also ran more ads than Clinton, particularly near the end, and that might have been helpful."

Why did the polls so badly underestimate the youth vote?

Polling firms have a number of ways to project how many young people will turn out to vote, and that leads them to different conclusions.

There are a few variables at play here. One is whom the polling firms decide to interview — some screen out for unregistered voters on the assumption that this group is less likely to vote. Others don't screen for registered voters (or are less strict about doing so) and instead look to gauge the adult population as a whole.

A separate question is how the pollsters take their interview samples and use them to create a projection of the electorate. Some pollsters create their models to give greater weight to voters who actually participated in previous elections. Other models, like Grossmann's, base their projections on whether someone says he or she is going to vote.

There is also the question of how the pollsters find the people who make up their sample. Many pollsters are still heavily reliant on landline phone calls, which probably undercounts young people, who tend to only have cellphones.

Grossmann's firm found Sanders and Clinton polling within the margin of error the week of the election. Grossmann said his results were probably more accurate in part because the firm used a very "lenient" screen for its interviews — rather than filtering out unregistered voters — and were generous in taking voters at their word when they said they planned to vote.

These factors help explain why some pollsters so dramatically underestimated the youth vote. But that doesn't say, Grossmann added, whether this is necessarily the "better" way to project vote totals — or if this was a particularly unusual result.

"[In] most elections, whether you voted last time is a better indicator than whether you say you're going to vote," Grossmann said.

How pollsters are hoping to get it right next time

Grossman noted this election was particularly difficult to forecast in part because this is the first competitive Democratic presidential primary in Michigan for more than a decade.

In 2008, Barack Obama's name did not appear on the ballot against Clinton because he never put his name on the ballot. In 2012, Obama ran unopposed.

There was also, Grossmann said, a wrong dismissiveness of the meaning of Sanders's youth outreach efforts. "The turnout operation that everyone was somewhat making fun of, including me, turned out to be successful," he said.

Mitchell raised other theories for why estimates of the youth vote were off, speculating that the particularly nice weather on election day encouraged young voter turnout more than had been predicted.

"Well, who would have voted if it was 18 degrees and cold? It was 70 and sunny, so anyone who is thinking about it did," Mitchell said.

Mitchell said his firm would be reevaluating how it gathered its samples to try to improve the accuracy of its polling ahead of the next set of primaries.

"We all got it wrong; we all got it wrong," he said. "And we have to figure out why we got it wrong, so we can figure out how to get right."