Mixing sulfur, saltpeter, and charcoal makes a black explosive powder. This was likely known at least a thousand years ago, although projectile weapons were a late development; early explosives were used for fireworks. Roger Bacon is often credited with rediscovering gunpowder in Europe, or possibly borrowing it from Middle Eastern sources, in the 13th century; the German monk Berthold Schwartz experimented with it slightly later.
Once you know the ratio of ingredients, black powder is very easy (though dangerous) to produce. But the ingredients would not be easily available to everyone in a preindustrial society in Europe. Sulfur has to be mined (mostly in Italy); saltpeter can be mined, and can also be manufactured by composting, but the latter method was not generally known in the Middle Ages. So, for a while, it seemed that rulers had a chance of keeping a lid on the ultimate weapon. Nevertheless the conspirators of the Gunpowder Plot in 1605 (still commemorated in England on Guy Fawkes Day) managed to smuggle nearly two tons of powder for a failed attempt to blow up the government.
In modern times, gunpowder is still made using basically the same formula, but amateur demolitionists and terrorists are more likely to use ammonium nitrate-based explosives, such as the one used in the Oklahoma City bombing. Ammonium nitrate produces a more powerful explosion than saltpeter, and is widely available in fertilizers and thus nearly impossible to regulate. EB