Second, higher levels of education are increasingly correlated with voting Democratic. This has been most starkly on display in the 2016 election, as polls suggest that Donald J. Trump may be the first Republican in 60 years to not win a majority of white voters with college degrees, even as he holds his own among white voters without degrees. But the trend of increasing Democratic identification among college graduates, and increasing Republican identification among non-graduates, was underway before Mr. Trump arrived on the scene. Today, Democrats hold a 12-point edge in party identification among those with a college degree or more. In 2004, the parties were even on that score.

Finally, in the United States the economic gap between the wealthiest cities and the rest of the country has grown considerably. The internet was supposed to allow wealth to spread out, since we could be connected anywhere — but the opposite has happened. Per capita income in the District of Columbia has gone from 29 percent above the United States average in 1980 to 68 percent in 2013; in the Bay Area, from 50 percent above to 88 percent; in New York City, from 80 percent above to 172 percent. Cities like New York, San Francisco, Seattle and Boston exert a strong pull on mobile, highly educated, Democratic-leaning voters, while at the same time stirring resentment in the less prosperous areas those voters leave behind. And these economically dominant cities tend to be in deep-blue states.

How extreme is Democratic clustering? If you compare President Obama’s 2012 performance with Al Gore’s in 2000, you can see a huge increase in the Democratic percentage of the vote in the 68 largest metro areas. But it barely budged everywhere else. Some of that increase was caused by voters already in those cities flipping from Republican to Democratic. But it was also the gravitational effect.

This clustering of Democrats helps explain why Mr. Trump has been keeping it close in Ohio and Iowa, both states where some 72 percent of white residents over 24 lack college degrees, the highest share among the 13 most competitive states.

It works the other way in presidential elections, too. Democrats have gained in some other swing states with high levels of college-educated voters, like Virginia and Colorado, and they do at least reap a benefit in the Electoral College for having a lock on big states such as New York and California.

But it’s another story in the Senate, where this dynamic helps explain why the Democrats are perpetually struggling to hold a majority. The Democrats have long been at a disadvantage in the Senate, where the populous, urbanized states where Democrats prevail get the same two seats as the rural states where Republicans are stronger. The 20 states where Republicans hold both Senate seats have, on average, 5.2 million people each; the 16 states where the Democrats hold both seats average 7.9 million people. Put another way, winning Senate elections in states with a total of 126 million people has netted the Democrats eight fewer seats than the Republicans get from winning states with 104 million people.