sodium chloride is a compound that is stable because its constituent elements namely chlorine and sodium have formed ionic bonds with each other and their outer energy shells are filled with 8 electrons.
Sodium on its own has 11 electrons. Two of these are in the 1st energy level, eight in the 2nd energy level and one in the 3rd energy level. This arrangement is highly unstable rendering the element sodium highly unstable and reactive. It will burst into flames immediately on exposure to air and can burn through human flesh if it comes into contact with it.
Chlorine at room temperature is a poisonous gas. It has 17 electrons in the arrangement 2:8:7 . The outermost shell has 7 electrons and so this element is fairly stable but will readily react with human lungs with fatal consequences.
So each of these two elements on their own are deadly, but when the two react together, sodium gives up its single electron on the outer energy shell to chlorine which readily accepts it and fills its outer shell to make 8 forming ionic bonds and is thus the two are completely stable and cannot explode or react in any other way because the outer shell of each of them is now filled with 8 electrons.