It all started in China around 850 C.E., when Chinese alchemists accidentally created gunpowder while trying to develop a "fountain of youth" potion. The resulting powder called huo yao, was a blend of charcoal, saltpeter and sulfur. They quickly learned the powder could be used in warfare. The then-reigning Song Dynasty is the first to have used gunpowder against the Mongols, whose constant invasions into the country plagued the Chinese throughout the period.
The Chinese attacked the Mongols with fire lances or "flying fire" — arrows fixed with tubes of gunpowder that, when ignited, would propel across enemy lines. More gunpowder-based weapons followed as the Chinese perfected a variety of weapons against the Mongols over the next centuries, including the first cannons and grenades. Gunpowder made its way to Europe in the 13th century, likely over the Silk Road trade routes through Central Asia. Rival nations refined gunpowder recipes in the ensuing centuries before arriving at the optimum mixture: approximately 75 percent saltpeter, 15 percent charcoal and 10 percent sulfur.
Historians generally consider the Chinese fire lance as the first gun. But before the 15th century, guns were tricky to fire — they required both hands and a burning wick to ignite the powder. Enter the invention of the lock, an internal firing mechanism that made shooting a hand-held firearm more efficient, easier and safer. The first was a matchlock, followed by a series of enhancements until we get something more akin to the guns we know today.
https://science.howstuffworks.com/innov ... st-gun.htm
Guns slowly replaced old-guard weapons, because they were more economical, rather than more lethal. Lifelong devotion was required to become a highly skilled (and highly paid) swordsman or archer, but a few weeks or months of training could turn a lower-class soldier into a skilled gunner. Besides increasing the field of soldiers, guns have had far-reaching influence on the nature of armed combat, from the distances at which dueling armies engage one another to the types of wounds soldiers incur. Only the horse — which dominated battlefields for millennia — has proven more important than the gun.
Firearms were first used for defense against external enemies, then rulers saw how they could be used to control their subjects. Males were physically stronger than females and were not burdened with pregnancy, so they dominated societies and cultures. And religion reinforced male dominance and even the rare female rulers reinforced it.
"Everyone is entitled to their own opinion, but not their own facts." - Daniel Patrick Moynihan