As shots fired inside a synagogue outside San Diego last month, Lori Gilbert-Kaye, 60, put herself in between the shooter and the rabbi and died as a result.

Riley Howell, 21, charged a gunman who burst last week into a University of North Carolina-Charlotte lecture room carrying a pistol. He too lost his life to save others.

And Tuesday inside a STEM school in Denver, Kendrick Castillo, 18, lunged at a fellow student who had pulled a gun in class, giving his classmates time to take cover. He was the lone student killed in the attack.

Mass shootings are now a nightmarish norm in the USA, and yet the tragedies often have a common thread of heroism in them as well – people whose heralded bravery and decisive actions helped stop the attacks and probably saved lives, sometimes at the expense of their own.

More:Kendrick Castillo, hero killed in Colo. school shooting, told his dad he would act if confronted with a gunman

The nation's three latest mass shootings, each occurring over an 11-day span beginning at the Chabad of Poway temple on April 27, have given us our latest heroes – just like shootings at a high school in Parkland, Florida, a Waffle House in Nashville, Tennessee, a synagogue in Pittsburgh and elsewhere did last year.

What made these ordinary citizens, in some cases kids, risk their lives for others? And what is it that will make future heroes undoubtedly do the same? Psychologists point to a wide range of characteristics, including patterns of taking risks and helping others, to help explain how some people can be so brave.

"You know, our life is all we've got," said Frank Farley, a psychology professor at Temple University who has studied heroism. "To put it on the line or take risks where you can lose your life for others is an astounding and profound human behavior."

The most recent act of heroism in the nation's series of deadly shootings came from Castillo, who just days before he was set to graduate from STEM School Highlands Ranch rushed a gunman who was barking orders to stay in place and not move.

"Kendrick lunged at (the gunman), and he shot Kendrick, giving all of us enough time to get underneath our desks, to get ourselves safe, and to run across the room to escape," Nui Giasolli, a fellow senior in the room, told NBC News.

More:What we know about the Highlands Ranch STEM school shooting in Colorado

Other students, including Brendan Bialy, an aspiring Marine, helped tackle the shooter to the ground. Two suspects are in custody in the Highlands Ranch, Colorado shooting. Castillo was killed, and eight students were injured.

Farley, a former president of the American Psychological Association, said there are "lifelong heroes" such as Martin Luther King Jr. or Mahatma Ghandi who commit their lives to a higher calling and "911 heroes" such as firefighters, police officers and other first-responders. And then there are "situational heroes," who – like Castillo, Howell and Kaye, emerge unexpectedly from a crowd during moments of crisis like a shooting.

"It's the most difficult to understand," Farley said of the latter group.

Many situational heroes are risk-takers, not risk-averse, Farley said. He said many also have traits of generosity, empathy and a desire to help. For some, religion or what they were taught growing up compels them to act – "You act because it's the right thing to do."

But "you can't put all these people all in the same box," he said. "It's a complex behavior. It's one of the least understood human behaviors that we know of."

More:Police escort honors Riley Howell, hero killed in UNC Charlotte rampage

Ronnie Glassman, a clinical social worker and professor at the Wurzweiler School of Social Work at Yeshiva University in New York, said people who step up as heroes in mass shootings tend to have a "moral center" and have a sense of "moral outrage" as a shooting unfolds.

"Kendrick Castillo, for him, these are his classmates, and there's that sense that 'I'm going to protect my classmates,'" Glassman speculated. "The morality of that – 'It's my role. I'm not going to let these people be hurt by someone who doesn't share my moral sense.'"

She likened his possible mindset to the "moral outrage" that she said Kaye would have had when the gunman entered the Chabad of Poway synagogue near San Diego: "How do you dare come into our sanctuary?"

Kaye was the lone person to die in the synagogue shooting. Three other worshipers were injured.

More:'Lori took the bullet for all of us': Rabbi lauds longtime friend, vows terrorism 'will not take us down'

In the case of Howell, the hero in the Charlotte shooting – in which two people were killed and four injured – Glassman noted that he played sports, including cross country and soccer in high school, and had aspirations to become a firefighter or join the military.

"There's that professional identity – I'm going to protect, help save," she said.

There's certainly an element of self-preservation at play, experts say, a quick calculation that the risk outweighs the danger of doing nothing. But if it was just about saving themselves, Glassman said, why would they step in front of a shooter?

Today, with mass shootings now in the national consciousness for two decades, most everyone – regardless of age, income, race or background – has had the chance to ask how they would react to a gunman.

Schools, in particular, have hardened to the violent reality. Shooting drills are now routine for most students. Some schools have metal detectors.

Perhaps nowhere is the threat of mass shootings more ingrained than in Denver, home of this week's STEM school shooting and where the 1999 Columbine High School shooting changed a generation. Just three weeks ago, much of Colorado was put on alert after a Florida woman infatuated with Columbine flew to Denver on the shooting's 20th anniversary.

"All those kids in that school shooting in Denver were part of that group that was re-traumatized yet again, and it's uppermost in their mind – how dare you do this to us again?" Glassman said. "We will not lose. We will fight back."

More:Woman 'infatuated' by Columbine shooting found dead of self-inflicted gunshot wound

In 15% of the 141 mass shootings from 2000 to 2017 that ended before police arrived, a potential victim of the attack stopped the attack themselves, according to research from the Advanced Law Enforcement Rapid Response Training (ALERRT) Center at Texas State University. In 34 cases, the attacker was physically subdued, and in nine cases the attacker was shot.

Pete Blair, executive director of Texas State's ALERRT, said he believe preparedness has played a role in people stopping shootings.

Organized training efforts for shootings have existed for several years, he said. His group has trained more than 140,000 first responders on shooting events since its inception in 2002.

Blair's group teaches people the motto "avoid, deny and defend" during an attack – avoid the shooter if possible, deny access if you can't avoid, and defend by seeking out the shooter only if other options are exhausted.

"The fact that you're preparing for these situations means there's a better chance that you'll respond effectively when something happens," Blair said.

"What we've seen in these last few cases is situations where – we would call it defending – they used fighting to try to stop the attack, and sometimes at the cost of their own lives, but they probably saved a lot of other lives in that process."