People have been making gunpowder for many centuries. The basic recipe is therefore well-known and looks like this: 75% Potassium nitrate, 15% Charcoal, 10% Sulfur
What you are trying to create with gunpowder is a fast-burning solid fuel. So you need a fuel, which in this case is the carbon in the charcoal. And you need oxygen, which you find in Potassium Nitrate. The sulfur is a second fuel and an accelerant – without it the gunpowder doesn’t burn fast enough, and it takes too much energy to ignite it.