# What causes KNO3 to decompose into KNO2 and Oxygen in gunpowder?

I've been studying fireworks and from what I understand:

$\ce{KNO3}$ decomposes to form $\ce{KNO2}$ and $\ce{O2}$ gas, and this free oxygen reacts with carbon to react with carbon and sulfur to form $\ce{CO2}$ and $\ce{SO2}$ gases in exothermic reactions.

What I don't understand is: What causes the $\ce{KNO3}$ to decompose, what is the purpose of using$\ce{KNO3}$ in gunpowder?

• Nitrogen's oxidation state in $\ce{KNO3}$ is +5,which is the maximum it can exhibit, so it tends to act as an oxidising agent, by releasing oxygen and getting reduced to a +3 state – Supernova Mar 18 '17 at 13:35

When Potassium Nitrate is thermally decomposed it forms Potassium Nitrite and Oxygen. $$\ce{2KNO3 -> 2KNO2 + O2}$$
If you had a mixture of Potassium Nitrate and Sucrose (table sugar), you would see something like this: $$\ce{5C12H22O11 + 48KNO3 -> 24K2CO3 + 36CO2 + 55H2O +24N2}$$