Ancient Chinese alchemists experimented with mixtures of substances. Their records gradually included formulas containing saltpeter, sulfur, and charcoal, practices connected with the formation of gunpowder.

Gunpowder was later used in fireworks and warfare. The gas and pressure generated by combustion helped drive the development of explosive devices, firearms, and other technologies.

China

The first confirmed references to what can be considered gunpowder in China occurred in the ninth century during the Tang dynasty. A formula appears in the Taishang Shengzu Jindan Mijue in 808, followed about fifty years later by a warning in the Daoist Zhenyuan miaodao yaolüe. The earlier text mentions a mixture of six parts sulfur, six parts saltpeter, and one part birthwort herb. The later account describes people heating sulfur, realgar, and saltpeter with honey. It warns that the resulting smoke and flames could burn the experimenters and even set their houses on fire. Such passages connect gunpowder's early history with alchemical experiments seeking an elixir of life. The destructive reaction emerged from work intended to produce a substance with very different properties.

This experimental medicine origin is reflected in its Chinese name huoyao, which means "fire medicine". Saltpeter was known to the Chinese by the mid-1st century AD and was primarily produced in the provinces of Sichuan, Shanxi, and Shandong. There is strong evidence of the use of saltpeter and sulfur in various medicinal combinations. A Chinese alchemical text dated 492 noted saltpeter burnt with a purple flame, providing a practical and reliable means of distinguishing it from other inorganic salts, thus enabling alchemists to evaluate and compare purification techniques; the earliest Latin accounts of saltpeter purification are dated after 1200.

The earliest chemical formula for gunpowder appeared in the 11th-century Song dynasty text Wujing Zongyao (Complete Essentials from the Military Classics), written by Zeng Gongliang between 1040 and 1044. The Wujing Zongyao provides encyclopedia references to a variety of mixtures that included petrochemicals—as well as garlic and honey. A slow match for flame-throwing mechanisms using the siphon principle and for fireworks and rockets is mentioned. The mixture formulas in this book contain at most 50% saltpeter — not enough to create an explosion, they produce an incendiary instead. The Essentials was written by a Song dynasty court bureaucrat and there is little evidence that it had any immediate impact on warfare; there is no mention of its use in the chronicles of the wars against the Tanguts in the 11th century, and China was otherwise mostly at peace during this century.

However, it had already been used for fire arrows since at least the 10th century. Its first recorded military application dates its use to 904 in the form of incendiary projectiles. In the following centuries the Chinese recognised gunpowder for its military applications and gunpowder was weaponised in the form of bombs, fire lances and hand cannons in China. Explosive weapons such as bombs have been discovered in a shipwreck off the shore of Japan dated from 1281, during the Mongol invasions of Japan.

By 1083 the Song court was producing hundreds of thousands of fire arrows for their garrisons. Bombs and the first proto-guns, known as "fire lances", became prominent during the 12th century and were used by the Song during the Jin–Song Wars. Fire lances were first recorded to have been used at the Siege of De'an in 1132 by Song forces against the Jin. In the early 13th century the Jin used iron-casing bombs. Projectiles were added to fire lances, and re-usable fire lance barrels were developed, first out of hardened paper, and then finally, the barrels were made out of metal to better withstand the explosive pressure of gunpowder. By 1257 some fire lances were firing wads of bullets.

In the late 13th century metal fire lances became 'eruptors', proto-cannons firing co-viative projectiles (mixed with the propellant, rather than seated over it with a wad), and by 1287 at the latest, had become true guns, the hand cannon, which included a metal barrel, touch hole and gunpowder chamber.