Although the dictionary definitions of these words are the same, they are often used slightly differently.
The word safety usually means protection from injury, accidents, and dangerous situations or substances. Seatbelts and airbags are safety measures to protect you in a car crash. Following regulations properly helps keep factory workers safe from accidents. If a nuclear reactor explodes, the people in the surrounding areas must be evacuated to safety.
The word security usually means protection from dangerous people (thieves, criminals, terrorists, etc.) A security guard helps protect a bank from robbers.
A country’s government is concerned about national security -protecting the country from invaders. Many security measures are taken to protect a country’s president from people who might want to try to kill him.
The one exception is when talking about the danger of being in certain neighborhoods, areas, or countries – you might say “It’s not safe to walk around the city at night” even though the danger is from people like thieves, attackers, rapists. It’s more natural to say “It’s not safe” rather than “It’s not secure.”
Finally, the word security also refers to something stable. If you have job security, it means your job will last a long time and you probably will not lose it.