Trains are fascinating places (full disclosure, I’m on a very un-fascinating train right now). Tens or hundreds of straphangers crowd into each car, standing within inches of each other and doing everything they can to pretend they’re alone. I’d venture to guess that most commuters would not rate crowds highly, and would covet some personal space. But not all personal space is great, and not all crowds are oppressive. Like magnets, the same individuals can attract or repel each other depending on the situation. Some fascinating research—including one very old and one very new project—have explored why.

One of my all-time favorite studies, conducted by Stanley Schachter in the late 1950s, examined whether fear might bring people together. Schachter convinced college-aged women that they would receive a series of electric shocks about 15 minutes later. Some were told that these shocks would barely tickle, and others were told they would be very painful. Participants were then asked whether they wanted to wait for their shocks in a room alone, or with other people. People who believed that shocks would be painful strongly preferred being near others, whereas those who believed the shocks would be mild generally did not care whether or not they had neighbors in their waiting room. On Schachter’s logic, this exposed a powerful rule about social behavior: in times of anxiety, people seek each other out. Like penguins in February, we tend to face adversity by huddling up.

Schachter refined this rule through a follow-up study. Some participants were given the option to be alone or with others who would also be shocked; others could wait alone or with people who would receive no shocks. When individuals could no longer wait with fellow shock-fearers, their preferences for company disappeared. This suggests that the benefit of crowds depends on our belief that others share our experiences. Schachter put this more poetically, claiming that his finding “removes one shred of ambiguity from the old saw ‘Misery loves company.’ Misery doesn’t love just any kind of company, it loves only miserable company.”

Just last week, a group of researchers from the University of Hertfordshire provided more evidence for the idea that people enjoy crowds with whom they share something. They tested this idea in a very different, more modern context: a Fatboy Slim concert in Brighton, UK. The organizers of this free show had expected about 65,000 people to attend, and instead got around 250,000. As the researchers put it, “Prima facie, therefore, this was a very crowded event.” Did these crammed concertgoers wish for more personal space? Sometimes, but not always. Specifically, people who identified with other audience members felt less crowded than people who did not, and as a result felt more positive emotions during the show.

Five and a half decades separates these studies, as does the difference between painful shocks and outdoor festivals. But these differences belie a key similarity. Both results suggest that crowds often feel more like company, especially when we need other people or feel connected to them. What about like-minded crowds appeals to us? Schachter speculated that they provide a freeing mask of anonymity, allowing individuals to “lose themselves” in the masses. And some music festivals certainly appear to provide such opportunities. Others suggest that similar crowds, such as partisan echo chambers, reinforce our judgments and make us more confident in our opinions. I think the power of groups might also go a bit deeper. One of our most fundamental human needs is that of belonging to a social group, and the right crowd can offer us a taste of such belonging.