Attacks of the magnitude of those that took place in Paris, killing 130 people and injuring more than 400, are extremely rare. The authorities do prepare for these emergencies but what advice is there for ordinary people?
Many survivors of the Paris attacks have said that they mistook the first gunshots for fireworks. This is typical, says John Leach, survival psychologist and military survival instructor.
People who are not expecting gunshots will assume that they are something else because it does not fit in with their expectations. "We respond to the model in our head and we don't respond directly to the environment and that is what makes us vulnerable," he says.
The time it can take to understand what is happening can be lethal. But if someone has already thought through a few worst-case scenarios then this process will be quicker. "All you need to ask is - if anything goes wrong, what is my first response going to be?" explains Leach.
It's easy to sit in a restaurant or cinema without paying any attention to the emergency exits. But knowing where they are can save lives. In the attack on the Bataclan concert hall on Friday, a security guard led a group of people to safety through the fire exit on the left of the stage.
The vast majority of people will be too confused to do anything during an attack. Leach has looked at life-threatening situations around the world and has found that only 15% of people will respond in a way that helps them survive. Up to 75% will just be too bewildered by what is happening around them to react at all. The other 10% will react in ways that reduce their chances of survival and get in the way of other people, he says.
Acting decisively might make survival more likely. But it's also human nature to wait for other people to act first. In a classic experiment, psychologists put people in a room and filled it with smoke to see how they would react. People who were on their own were more likely to take action than those who were with other people.
Make yourself a smaller target
"Where there's cover from sight, there's cover from fire," advises Ian Reed, a former British soldier, military instructor and chief executive of the Formative Group security firm. The first thing is to try to get out of the way and make yourself a smaller target. This can involve simply dropping to the ground but ideally means getting behind some sort of cover.
Hard cover such as a concrete wall is the best option. "Obviously, Hollywood has portrayed cars as being bulletproof but that's not necessarily the case," says Reed. Despite this, even a car is better than nothing at all.
When an attack happens in a tightly packed space, a single bullet can end up injuring several people. Keeping out of sight reduces the risk that you can be targeted deliberately and also the chances of being hit by someone simply spraying the room with fire.
Many survivors in Paris did this instinctively - turning tables over to use as makeshift shelters or hiding behind speakers in the concert hall. But the lack of cover on the main floor of the Bataclan meant not everyone there was able to hide.
An Irish couple survived by playing dead. Another survivor, Theresa Cede, told the BBC: "One guy was badly hurt, and moaning, so we tried to say: 'Shh, be quiet, stay alive and don't move,' because every time there was movement somewhere, there were more gunshots."
"They are looking for movement - it will catch their eye," explains Reed. This is especially true if it's dark. Some people in the Bataclan did run for the exit when the attackers paused to reload. This can be risky, but in some scenarios running away is a good idea.
The UK government's advice, in its document on "dynamic lockdowns", is to run if there is a safe route out. But if there is no safe way to do this it advises hiding. The advice is summarised as "run, hide, tell".
According to eyewitnesses on Friday, several people chose to stay hidden in offices and toilets until help arrived.
In January, 24-year-old Lassana Bathily was hailed a hero after hiding Jewish shoppers in a basement cold store during an attack by an Islamist gunman. He switched off the fridge and the lights and ran to get help. All of those he hid survived.
Rushing a gunman has worked in some situations. In August, a train attack was foiled in France after passengers overpowered the lone gunman. But of the four passengers involved in subduing him, one was in the Air Force and another in the National Guard. The men only made the attempt after the shooter's weapon jammed.
Reed says that it's not a good idea to take on an assailant without training. "It's just risking your life," he adds. It's important to remember that many attackers will be working in teams. Some will be wearing body armour and others could be carrying explosives.
Adel Termos is thought to have saved dozens of lives in Beirut last week after he tackled a bomber from behind. But the suicide vest exploded and both Termos and the bomber died in the blast.
Despite the dangers, some people argue that it's important to be ready to fight if necessary. Members of the Islamic State group are not motivated by taking hostages, says James Alvarez, psychologist and hostage negotiator. "There's nobody to negotiate with. Your value lies in you being dead. If I know that I'm going to be shot, I'd like to think that I'm not going to go down quietly."
After the escape
Once someone has managed to escape the situation it's important for them to remain vigilant. "Get as far away as possible, behind as much hard cover as possible and go to the nearest authority figures for help," says Reed.
It can be dangerous to join big groups nearby and to take public transport. "Always assume that there's going to be a secondary device or action," adds Reed. The key is to take advice from police officers or other officials, as they may have better knowledge of the situation.
Help each other
The chances of being caught up in a major attack are still low. But if it does happen, co-operating with others can increase people's chance of survival, says Chris Cocking, social psychologist and expert in crowd behaviour.
After the 7/7 London attacks, Cocking helped interview dozens of people involved and concluded that the quickest and most efficient way for a group to evacuate is for people to work together.
This is the only way to avoid situations such as a crowd getting jammed at a fire escape. Cocking says that most people are likely to try to help each other even in extreme situations. "There's an assumption that it's everybody for themselves but that just doesn't happen," he says.
Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.