What’s even stranger about this relationship is that even though the richest counties tend to be more Democratic, well-to-do people actually tend to vote Republican. Although some political pundits might have you believe Democrats are the party of the rich, urban elite (pdf), exit polls from 2016 and 2018 show that people in households with less than $50,000 in income are significantly more likely to vote Democratic. The relationship between lower incomes and voting Democratic has been true for decades. It is not quite as strong as it once was—in 2016 Clinton substantially underperformed Al Gore, who ran for president in 2000, with the poor—but the relationship persists.

So how can this be? How can Republicans do better among the richest Americans but worse in the richest counties? And how do Democrats do so well in the very richest places, when their strength is among low-income Americans? The high rates of Democratic voting in the poorest counties is the only fact that, on the face of it, makes sense.

In his book, Red State, Blue State, Rich State, Poor State: Why Americans Vote the Way They Do, the Columbia University professor Andrew Gelman examined these paradoxes. Rather than look at counties, Gelman’s book examined how Democrats won the nation’s richest states, like California, New York, and Massachusetts, while losing the rich. The answer is that though the richest counties and states tend to go for Democrats, within those places, the rich are still more likely to vote for Republicans than Democrats. It’s just that the places with lots of Democrats tend to be richer.

Take Kentucky and New York: the former is a Republican stronghold and the latter is reliably Democratic. In both states, the rich are more likely to support Republicans than are the poor. But, overall, Kentucky voters tilt toward Republicans and New York voters tilt toward Democrats—poor Kentuckians were less likely to vote for Trump than rich New Yorkers.  Since New York is richer than Kentucky, it makes it seem like Democrats are the party of the rich.

That’s the statistical explanation, but it doesn’t answer why Democrats consistently do well in places that happen to be richer.

The main reason Democratic states tend to be richer, even though Democratic voters are not, is that the Democrats have become the party of cities. All of the densest counties in the US vote for Democrats, most of them overwhelmingly so, and, on average, city dwellers tend to have higher incomes than rural Americans. (This also explains why Clinton could win the popular vote while carrying less than 40% of most counties: because Democrats do well in cities, she won big in the most populous ones.)

William Frey, a demographer with the Brookings Institution, tells Quartz that the urban preference for Democrats comes down largely to views on religion and diversity. Urbanites of all incomes tend to be more secular and pro-choice. They are also more likely to be people of color, or know other people of color, says Frey, and believe in the importance of promoting diversity through programs like affirmative action. In counties where over 90% of the population identifies as white, the GOP averaged 70% of the vote in 2016, compared to 43% in counties with where whites were a minority.

It is not the rich in the richest places that make them so Democratic, but the middle class. Working-class teachers, bus drivers, and carpenters are very likely to be Democratic in urban counties, and they make more money than the middle class in rural areas. They are the reason Democrats win in rich places without winning the rich: Democrats are the party of, among other groups, the urban middle class.

We can see this relationship if we zoom in a bit closer geographically. Data on income and voting choice is not available at an individual level, but we can go beyond counties and look at neighborhoods. Quartz examined voting by census tract in Alameda County in California, which contains the cities of Oakland and Berkeley (Census tracts are neighborhoods of about 2,000-8,000 people).

In 2016, almost 80% of the voters in Alameda County went for Clinton. But even inside this left-leaning county, income is strongly related to who you vote for. Voting precinct level data show that in almost all of the census tracts where median household income is below $40,000, more than 90% of people voted for Clinton. In some of the richer tracts, less than 70% voted for her.

If the urban-rural divide explains why rich places vote Democrat, what about poor places? Why do the very poorest counties go for Democrats as well? Like so many things about America, it comes down to race. Many of the poorest counties in the US are rural Southern counties with large Black populations. Frey has collected data on the racial and ethnic makeup of the 40 poorest counties in the US, and it shows that 28 of those counties are majority-Black places in Southern states. Black Americans are extremely likely to vote Democratic, regardless of income and population density, because of the Democratic party’s history of supporting anti-discrimination legislation. In the 1940s, Black voters were evenly split between Democrats and Republicans, but during the civil rights movement of the 1950s and 1960, they swung dramatically toward Democrats. Today, nearly 90% of Black voters in the US identify as Democrats or lean Democratic.

All of this suggests that to understand American politics you have to start with both urbanization and race. The US economy is powered by incredibly productive cities and its politics are increasingly oriented around a divide between those who live in them and those who don’t. Few divisions in America are large enough to supersede that one, and the exception is the country’s long and shameful history of racial discrimination.

📬 Sign up for the Daily Brief

Our free, fast, and fun briefing on the global economy, delivered every weekday morning.