Against your natural response, you should try as much as can to remain calm when there's a sudden explosion. This mainly because explosions are of different types and can be caused by different factors, you therefore need to try to identify the type and cause of the explosion to help you effectively deal with the problem. Sometimes, it might not even be an actual explosion you're dealing with, but an explosive sound that might have been caused by nothing too serious.
Be as Rational as Possible
In a sudden event, there is a tendency to lose all sense of rationality and react with fear, rather than think with your brain. Avoid this. You need to understand that without being able to rationally assess the situation, you're likely to make costly and even deadly mistakes. If you can calm down enough to think rationally, rather than screaming and overreacting, you're more likely to successfully get out of the situation.
Try To Take Cover
If the explosions happen outdoors, try to take cover behind any shield or shelter around you. Ensure the shield is unable to conduct electricity and is reasonably sturdy. Use the time you're taking cover to try to assess the situation and see if there is need for concern. Finding a place to take cover can also help keep you safe in the event of crowd chaos or a stampede.
Attend to Loved Ones
If you are not alone and you're caught up in the incident with family and friends, after you've taken cover and assessed the situations, you can then try to help the loved ones around you. Remember that you need to 'put your oxygen mask on first', therefore you need to first be okay before you can successfully save anyone.
Turn Off Electrical Appliances and Clear all Possible Exits
If you're indoors, immediately turn off all electrical appliances around you. If it's possible, try to turn them off at their central point. Try to get your hands on a fire extinguisher, if you have one. Then, try to find and clear an exit for yourself and other loved ones that might be around or with you. Ensure you have a phone or communication device on you as you exit.
The moment you have been able to identify the explosive sound with an actual or likely dangerous explosion, immediately call a local emergency response team and report the incident to them. If you're not able to reach an emergency response team, call anyone you know that might be able to help. Also, if you have access to the internet, immediately post a live or recorded video of the incident and copy or mention rapid response agencies that might be able to help.
Try to Leave the Area
If you can, try to leave the area and get as far away as possible. Please avoid downplaying the importance of an explosion and sticking around believing that nothing serious will happen. It's called an explosion for a reason. Even in the event of a mere explosive sound, you still need to be careful and get away from the area for a while to be sure it does not escalate into an explosion.