What you think is funny and what you think is downright offensive says a lot about you.

In this episode of Hidden Brain, Shankar Vedantam explores why some of us think, say, jokes about nut allergies are hilarious, while others are already crafting angry emails to NPR.

Gender, race, cancer, your mom—these are touchy subjects, but also ones that garner big laughs. Why? Comedian Margaret Cho explains it this way: "You're laughing because someone is actually playing with fire, and this may erupt into something incredibly explosive."

Shankar talks with evolutionary anthropologist Robert Lynch at the University of Missouri to ask when people laugh at jokes. Lynch presented volunteers with jokes about men, women and the wage gap. He measured who laughed. (Hint: being a man was not a prerequisite.) Lynch found in his research that the volunteers' propensity to laugh about the gender wage gap was shaped by their unconscious biases.

Lynch gave people an implicit association test, which gauges how strongly different concepts are linked in the brain. Then he had them watch a half-hour stand-up skit of notoriously funny-offensive line-crosser Bill Burr. Lynch didn't just ask who thought Burr's jokes were funny — he videotaped the volunteers and analyzed their facial expressions.

He found that participants with more traditional gender attitudes laughed more readily at the joke about the wage gap.

Lynch offered a reason why people laugh at jokes that mirror their internal views: Evolution. He says laughter signals to others what's going on in our heads. When two people laugh at the same joke, they subtly communicate to one another that they think the same way.

"A lot of laughter is about taboo topics . . . so it's communicating something that we may not be so readily willing to admit, but we're communicating it to other people to find out if they share our preferences," Lynch says. "It's kind of a coded message, saying, 'hey, are you part of my group?'"

Later in the episode, Shankar sits down with NPR arts reporter Elizabeth Blair to watch a bit from Louis C.K, who lives on the line between funny and offensive.

They discussed a range of social science research into what makes jokes funny. One idea: Jokes offer a mechanism for catharsis.

"When I walk out of a great show, it forces me to be a bit more authentic with my feelings," Blair says. "We all have some really dark thoughts. That's human."

Finally, Shankar and Elizabeth call up Burr to ask why he takes his audience to uncomfortable places — such as a recent joke about Caitlyn Jenner. They also discuss research by Peter McGraw about benign violations — the idea that jokes need to violate taboos to be funny, but they also need to be safe. For example, if your kid has ever experienced anaphylactic shock, you're probably not laughing at jokes about peanut allergies.

Copyright 2016 NPR. To see more, visit http://www.npr.org/.