The history of the firearm begins in 10th-century China, when tubes containing gunpowder projectiles were mounted on spears to make portable fire lances. Over the following centuries, the design evolved into various types, including portable firearms such as flintlocks and blunderbusses, and fixed cannons, and by the 15th century the technology had spread through all of Eurasia. Firearms were instrumental in the fall of the Byzantine Empire and the establishment of European colonization in the Americas, Africa, and Oceania. The 19th and 20th centuries saw an acceleration in this evolution, with the introduction of the magazine, belt-fed weapons, metal cartridges, rifled barrels, and automatic firearms, including machine guns.

Older firearms typically used black powder as a propellant, but modern firearms use smokeless powder or other propellants.

There are reports of some sort of incendiary chemical weapon, the Greek fire, used by the Eastern Roman Empire (Byzantine Empire) from the 7th through the 14th centuries, which may have been delivered through grenades and/or by some kind of flamethrower. However, its nature is still being debated, and it does not seem related to ancient Chinese or modern firearms.

10th to 12th centuries

The first firearms were invented in China, following the invention of gunpowder. The earliest known depiction of a gunpowder weapon is the illustration of a fire lance on a mid-10th century silk banner from Dunhuang. The fire lance was a tube, made of paper and bamboo, filled with black-powder and attached to the end of a spear, which was used as a flamethrower. Shrapnel or pellets were sometimes placed in the barrel so that they would fly out together with the flames. The De'an Shoucheng Lu, an account of the siege of De'an in 1132 during the Jin–Song Wars, records that Song forces used fire-lances against the Jurchen.

The earliest depiction of a gun is a sculpture from a cave in Sichuan dating to the 12th century. It depicts a Chinese figure carrying a vase-shaped bombard with flames and a cannonball emerging from it.

The proportion of saltpeter in the propellant was increased to maximize its power. To better withstand that power, fire lance barrels were made of metal. At the same time, the shrapnel was replaced by projectiles whose size and shape filled the barrel more completely. The result was the hand cannon, with a metal barrel, high-nitrate gunpowder, and a properly sized projectile.

13th century

The oldest surviving firearm is the Heilongjiang hand cannon dated to 1288, which was discovered in modern-day Acheng District where the History of Yuan records that battles were fought. Li Ting, a military commander of Jurchen descent, led foot soldiers armed with hand cannons to suppress the rebellion of the Eastern Christian Mongol Prince Nayan.

Kublai Khan's mostly failed invasion of Vietnam and of Java (1258–1288) may have spread the knowledge of making gunpowder-based weapons to Southeast Asia. There is evidence of that knowledge in the Nusantara archipelago. A stele inscription by Trương Hán Siêu dated to 1312 recorded guns and shots ("súng đạn") among the loot that the Vietnamese obtained from the Chams in a campaign.Đông Nguyễn, Kaovjets Ngujens (2023). Lôi Động, Tinh Phi. NXB Dân Trí. p. 75. It indicates that both polities had knowledge of guns and even employed them well before that date.

Ahmad Y. al-Hassan claimed that the Battle of Ain Jalut in 1260 pitted the Bahri Mamluks against the Mongol Empire. "The first cannon in history" used gunpowder almost identical with the ideal composition for explosive gunpowder. However, Iqtidar Alam Khan argued that it was the invading Mongols who introduced gunpowder to the Islamic world. and cites Mamluk antagonism towards early riflemen as an example of how gunpowder weapons were not always accepted..

14th and 15th centuries

Firearms appeared in the Middle East between the late 13th and early 14th century. "The Europeans certainly had firearms by the first half of the 14th century. The Arabs obtained firearms in the 14th century too, and the Turks, Iranians, and Indians all got them no later than the 15th century, in each case directly or indirectly from the Europeans. The Koreans adopted firearms from the Chinese in the 14th century, but the Japanese did not acquire them until the 16th century, and then from the Portuguese rather than the Chinese."

The first references to what may have been arquebuses () made by the Janissary corps of the Ottoman military date them to between 1394 and 1465. However, by as late as 1444, it is unclear whether these were truly arquebuses or rather small cannons. The fact that they were listed separately from cannons in mid-15th century inventories suggests that they were handheld firearms.

The musket first appeared in the Ottoman Empire by 1465. In the Shen Qi Pu (神器譜), a firearms manual written in 1598, Chinese firearm designer and writer Zhao Shi Zhen described Turkish muskets as superior to European muskets. At some point before 1598, Turks developed a pivoting matchlock mechanism that was later modified by Zhao into the first mechanism using rack and pinion.

One major obstacle preventing matchlock guns from large-scale adoption was complaints that strong wind and rain could either blow away or ruin priming powder placed in the flash pan. Mentioned in Shen Qi Pu, Zhao later developed the "Xuanyuan arquebus" (, named for the Yellow Emperor), which used a novel rack-and-pinion mechanism. This firing mechanism was connected to both the serpentine and flash pan cover and designed so that whenever the trigger is pulled, the serpentine was lowered at the same time as flash pan cover opened, minimizing the priming powder's exposure to open air and thus reducing the risk of priming powder being blown away by strong wind or spoiled by rain. The combination of a trigger-operated flash pan cover and small copper rain cover mounted on a pendulum was considered a more sophisticated approach to the Japanese solution of covering the entire firing mechanism with a lacquered box, which could hamper aiming, shooting and reloading. The Chinese military book Wubei Zhi (1621) describes Turkish muskets that used similar rack and pinion mechanisms, which were not known to have been used in European firearms at the time.

A pole gun, the bedil tombak, was recorded in Java in 1413,Mayers (1876). "Chinese explorations of the Indian Ocean during the fifteenth century". The China Review. IV: p. 178. The knowledge of making "true" firearms came after the middle of the 15th century. It was probably brought by Arab traders no earlier than 1460. Before the arrival of the Portuguese in Southeast Asia, primitive firearms in the form of the Java arquebus was already present.

The technology further improved after the Portuguese capture of Malacca (1511).Andaya, L. Y. 1999. Interaction with the outside world and adaptation in Southeast Asian society 1500–1800. In The Cambridge history of southeast Asia. ed. Nicholas Tarling. Cambridge: Cambridge University Press, p. 345–401. Starting in 1513, German, Bohemian and Turkish gun-making traditions merged.The bewitched gun : the introduction of the firearm in the Far East by the Portuguese, by Rainer Daehnhardt 1994. This resulted in the Indo-Portuguese tradition of making matchlocks. Indian craftsmen modified the design by introducing a short, almost pistol-like buttstock held against the cheek, not the shoulder, when aiming. They reduced the caliber and made the gun lighter and more balanced. The Portuguese, who conducted much fighting aboard ships and rivercraft, valued a more compact gun, and thus this approach became popular. Malay gun founders, regarded to be on the same level as German gunsmiths by the Portuguese, quickly adapted these new firearms and birthed a new type of arquebus, the istinggar.

South Asia

The first recorded use of firearms in South Asia was at the Battle of Adoni in 1368. In the Deccans, the Bahmani sultanate led by Mohammed Shah I used a train of artillery against the Vijayanagara Empire under Harihara II. The first recorded firearms in Đại Việt were used against the Champa king Chế Bồng Nga in 1390. He was killed by a volley of cannons known in Chinese as Huochong; one cannonball blasted through the ship planks before hitting the king, killing him instantly.Chinese Gunpowder Technology Technology and Dai Viet, ca. 1390 -1497. Sun Laichen. In Vietnam Borderless Histories Eds Hnung Tuyet Tran & Anthony Reid, University of Wisconsin Press 2006 Their use by Sultan Mohammed Shah of Gujarat in the fifteenth century was recorded. When the Portuguese reached India in 1498, they brought with them firearms, among them the matchlock musket and man-of-war (ships) armed with cannons. Portuguese travelers observed that firearms there were already in use. Peasants of the Gangetic plains used cheap handguns made by local blacksmiths. Travancore, Kashmir, Rajasthan, Punjab and Sindh hosted sites of arms manufacture. In the early 16th century, Zamorin of Calicut, had begun to emulate the Portuguese and began to arm his ships with naval gun pieces, combining local and imported technology.

In the 16th century, Central Asian prince Babur, the first Mughal emperor, brought Turkish firearms, which Mughal adversaries used against the Delhi Sultanate in the First Battle of Panipat, which the Rajputs and the Afghans in turn adopted. Across the 16th and 17th century, firearms played an important role in the Mughal military. Known as the tufang, Mughal emperor Akbar introduced many improvements in the matchlock.

Firearms were also developed by the Marathas, although weaker than their counterparts such as the Mughals and Mysore. Balaji Baji Rao organised the arm in professional lines and Madhavji Sindhia established a more efficient gun foundry under the supervision of European gun makers. During the 18th century, Tipu Sultan was notable for effective use of guns, mortar, rockets and howitzers; the Nizam of Hyderabad manufactured guns with the help of French officers, while Sikhs under Maharaja Ranjit Singh pioneered the development of horse-artillery on the same lines as that of the East India Company.

Europe

One theory of how gunpowder came to Europe is via the Silk Road; another holds that it arrived 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 the Siege of Calais (1346–47).David Nicolle, Crécy 1346: Triumph of the longbow, Osprey Publishing; June 25, 2000; .

The first mention of firearms in Russia is found in the chronicle, which stated that during the 1382 defense of Moscow from Tokhtamysh's Golden Horde, Muscovites used firearms called (), which were of Eastern origin; this word derives from Turkic "gun".

Around the late 14th century in Italy, smaller, portable hand-cannons or were developed, creating in effect the first smoothbore personal firearm. The earliest surviving firearm in Europe was found in Otepää, Estonia. It dates to at least 1396.