The first device identified as a gun, a bamboo tube that used gunpowder to fire a spear, appeared in China around 1000AD. The Chinese had previously invented gunpowder in the 9th century. An early type of firearm (or portable gun) is the fire lance, a black-powder–filled tube attached to the end of a spear and used as a flamethrower; shrapnel was sometimes placed in the barrel so that it would fly out together with the flames. The earliest depiction of a gunpowder weapon is the illustration of a fire-lance on a mid-10th century silk banner from Dunhuang. The De'an Shoucheng Lu, an account of the siege of De'an in 1132, records that Song forces used fire-lances against the Jurchens. In due course, the proportion of saltpeter in the propellant was increased to maximise its explosive power. To better withstand that explosive power, the paper and bamboo of which fire-lance barrels were originally made came to be replaced by metal. And to take full advantage of that power, the shrapnel came to be replaced by projectiles whose size and shape filled the barrel more closely. With this, we have the three basic features of the gun: a barrel made of metal, high-nitrate gunpowder, and a projectile which totally occludes the muzzle so that the powder charge exerts its full potential in propellant effect.
One theory of how gunpowder came to Europe is that it made its way along the Silk Road through the Middle East; another is that it was brought to Europe during the Mongol invasion in the first half of the 13th century. English Privy Wardrobe accounts list "ribaldis," a type of cannon, in the 1340s, and siege guns were used by the English at Calais in 1346. The earliest surviving firearm in Europe has been found from Otepää, Estonia and it dates to at least 1396. Around the late 14th century in Europe, smaller and portable hand-held cannons were developed, creating in effect the first smooth-bore personal firearm.