The chemistry used in guns is not limited to gunpowder. In order to make the gunpowder explode, a primer is needed. A primer is an explosive that will detonate when it is hit by the firing pin in the gun.
You may have seen “strike anywhere” matches, which burst into flame with just a little friction. They can also be lit by hitting them with a small hammer. They are made from sulfur and phosphorus, with an oxidizer that is more powerful than potassium nitrate, such as potassium chlorate. A mixture like that could be used as a primer in a bullet cartridge. But some specialized contact explosives have been invented for just this purpose.
One of the early contact explosives used in primers is mercury fulminate. It is not as corrosive as contact explosives made with potassium chlorate, so it did less damage to the gun.
Other contact explosives have replaced mercury fulminate as primers in modern weapons. Lead azide, lead styphnate, and a class of compounds called tetrazenes are now used. All of these contact explosives are molecules that come apart very easily, and release a lot of energy very quickly when they come apart and the atoms rearrange themselves.
Lead azide – a contact explosive