This piece originally appeared on Pacific Standard.

Does your next-door neighbor vote the same way you do? How about the couple who live across the street, or your friends on the next block?

The odds you answered “yes” or “probably” to those questions have increased dramatically in recent decades. Forget red states and blue states: We’re increasingly living in red or blue counties, cities, even neighborhoods.

This phenomenon has been widely cited as one reason behind our current political polarization: It allows strident voices on the right and left to fairly insist they’re fairly representing their constituents. But why exactly are we engaging in this sort of ideological segregation?

Newly published research suggests this double-edged dynamic is driven by a basic psychological pull.

“Individuals choose to live in communities with ideologies similar to their own to satisfy their need to belong,” writes a research team led by social psychologist Matt Motyl of the University of Virginia. That deep-seated desire is a major factor driving this migration, he and his colleagues write in the Journal of Experimental Social Psychology.

Unfortunately, this appears to be a clear case where individual contentment and the national interest are at odds. While “This homogenization of communities may promote greater personal well-being,” the researchers write, “it may also foster increased partisan hostility” by minimizing our contact with people on the other side of the ideological divide.

Motyl and his colleagues describe a series of studies providing evidence that the strong pull of belongingness plays a huge role in our desire to move to ideologically cohesive areas.

The first study featured a huge sample of just over one million U.S. residents who visited the Project Implicit website. The researchers focused on their responses to three items on the site’s questionnaire: their political ideology (on a one-to-seven scale from liberal to conservative); the zip code “where they resided for the greatest length of time;” and their current zip code.

Their responses were analyzed in the context of a “social climate data base” that included the percentage of people in each zip code who voted for President Obama or John McCain in the 2008 presidential election.

The results: “Partisan participants who previously lived in communities with values different from their own were more likely to migrate than those who lived in communities with values similar to their own.” Moreover, those who moved tend to do so to zip codes that better matched their political ideology.

“The likelihood of migration was particularly large among strong liberals and strong conservatives,” they write. “Moderates were less likely to migrate at all.”

The second study directly addressed the importance of feeling a sense of belonging. The participants—1,236 people who registered with the research website yourmorals.org—responded to statements such as “I feel like I belong in my current city/town.” They estimated the percentage of residents in their area who shared their political values, and gave their zip code information as in the first study.

Not surprisingly, the researchers found “the greater ideological fit people perceive in their community, the more they feel like they belong in that community.” More importantly, they also found a relationship “between sense of belonging and the desire to migrate.”

The third study looked at this issue still more directly. Participants—102 University of Virginia undergraduates—reacted to a news article about “the changing political landscape of colleges.” Some read a version that said their school was “increasingly attractive to conservatives.”

All were then asked a series of questions describing their satisfaction with the university, and whether they felt they belonged. Researchers report those in the “ideological misfit condition”—that is, liberals who were informed their student body was becoming more conservative—reported “a reduced sense of belonging and a greater desire to transfer to another school.”

Motyl and his colleagues note that relocating to a place where you feel comfortable has a wide range of psychological benefits. “When people feel like their values match their environment, they experience greater subjective well-being and increased self-esteem,” they write. “Without fear of reprisal for expressing one’s values, one may be able to more easily form strong interpersonal bonds and accumulate social capital.”

But then there’s also a larger societal cost. “Ideological segregation necessarily leads to reduced contact between members of the segregated groups,” they add. “There is a long history of research demonstrating that reduced intergroup contact lays the foundation for future conflict and prejudice.

“Ideological migration might increase ‘bonding’ with similar others, but decrease ‘bridging’ with dissimilar others.”

Of course, the choice to move to a specific city or neighborhood is based on many factors, including “good job opportunities, safety, and clean air,” Motyl and his colleagues concede. So while the desire to be surrounded by like-minded people clearly matters, the opportunity to buy the home of your dreams at a price you can afford may be strong enough to override it.

But even if you live in a “mixed neighborhood” (that is, liberals and conservatives),there’s another way to stay comfortably in your bubble and feel a sense of community. You can always smile and wave at your crazy neighbor, close the door and turn on your favorite partisan cable news channel.