Gunpowder was invented in the 9th century and firearms in the 12th century in China. These inventions were later transmitted to the Middle East and to Europe.
Firearms in China
The direct ancestor of the firearm is the fire-lance, a gunpowder-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 Tê-An Shou Chhêng 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.
The earliest depiction of a gun is a sculpture from a cave in Sichuan dating to the 12th century of a figure carrying a vase-shaped bombard with flames and a cannonball coming out of it. The oldest surviving gun, made of bronze, has been dated to 1288 because it was discovered at a site in modern-day Acheng District where the Yuan Shi records that battles were fought at that time; Li Ting, a military commander of Jurchen descent, led foot-soldiers armed with guns—including a Korean brigade—in battle to suppress the rebellion of the Christian Mongol prince Nayan.
Firearms in the Middle East
The Arabs obtained firearms in the 14th century. Al-Hassan claims that the Battle of Ain Jalut in 1260 saw the Mamluks use against the Mongols in "the first cannon in history" gunpowder formulae which were almost identical with the ideal composition for explosive gunpowder. However, Khan states that it was invading Mongols who introduced gunpowder to the Islamic world and cites Mamluk antagonism towards early riflemen in their infantry as an example of how gunpowder weapons were not always met with open acceptance in the Middle East.
Firearms in the West
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 first mention of firearms in Russia is found in the "Sofiiskii vremennik" chronicle, where it is stated that during the 1382 defense of Moscow from Tokhtamysh's Golden Horde, Muscovites used firearms called "tiufiaks" (Russian: "тюфяки", which were of Eastern origin; this word derives from Turkic "tüfeng", meaning "gun").
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. In the late 15th century the Ottoman empire used firearms as part of its regular infantry. As the centuries progressed, these hand-held cannons evolved into the flintlock rifle, then the breech loader and finally the automatic weapon.
Early firearms had to be cocked and caught by the "sear," which holds the hammer back, before each shot. Pulling the trigger allows the hammer or striker to fly forward, striking the "firing pin," which then strikes the "primer," igniting an impact-sensitive chemical compound (historically, first fulminate of mercury, then potassium chlorate, now lead styphnate) which shoots a flame through the "flash hole" into the cartridge's propellant chamber, igniting the propellant.
The Springfield Armory in Springfield, Massachusetts became important to the history of firearms during the 1850s, when it debuted the Springfield rifle. Springfield rifles were among the very first breech-loading rifles, starting production in 1865. By that time, metallurgy had developed sufficiently so that brass could be worked into fixed ammunition. Previously, each round was custom made as needed: the shooter poured loose powder down the barrel, used leather or cloth for wadding if time allowed, selected a suitable projectile (lead ball, rocks, arrow, or nail), then seated the projectile on top of the powder charge by means of a ramrod. Performance was erratic. Fixed ammunition combined a primer, the pre-measured charge, and the projectile in a water-resistant brass cartridge case. Most importantly, the soft brass expanded under pressure of the gas to seal the rear end of the barrel, which prevented the shooter from being maimed by escaping high-pressure gases when he pulled the trigger.
A repeating firearm or "repeater" is a firearm that holds more than one cartridge and can be fired more than once between chargings. The most well-known repeater is the American, Springfield Model 1892-99 -- also made at the Springfield Armory in Springfield, Massachusetts -- which were used during the Spanish-American War. Some repeating firearms require manipulation of a bolt, (as in bolt action), lever, or slide to eject the fired cartridge case, draw a fresh cartridge from the magazine, and insert it into the firing chamber, and "cock" (draw to the rear and place under spring tension) the hammer or striker, so that pulling the trigger will fire the weapon. Others use either the firearm's recoil, or a small portion of the propellant gas drawn from the barrel, to operate the firearm's mechanism and ready it for the next shot. Such firearms are sometimes called "self-loading," but are more commonly known as semi-automatic, if they fire one shot for every pull of the trigger, or automatic or "full-auto" if they continue to fire until the trigger is released or the magazine is empty. A revolver is a unique type of firearm in which a rotating cylinder holds a number of cartridges; the cylinder "revolves" to align each "chamber" or "charge hole" with the rear of the barrel, hold the cartridge and contain the pressure (up to 65,000 pounds per square inch or 450 MPa) produced when the cartridge is fired. Thus the cylinder serves as both magazine and firing chambers. There are also "single- shot" and multiple-barrel firearms, which hold only one cartridge per barrel and must be reloaded manually between shots.
The earliest repeating firearms were revolvers (revolving rifles were sometimes called "turret guns") and were "single action" in that they could only be fired one way: by manually cocking the mechanism (drawing the hammer to the rear with the thumb) before each shot. This design dates from 1836, with the introduction of the Colt Paterson, or even earlier. Though they are slower to reload and fire than some other types of firearms, single-action revolvers are of a simple, strong design, and are still made, though they are nowadays used more often for hunting than for self-defense. The double-action revolver is a design almost as old as the single action. A double-action revolver can be fired in either of two ways. One can cock the hammer (the action of which moves levers to rotate the cylinder and align a fresh cartridge with the rear of the barrel), then pull the trigger for each shot ("single-action mode") or one may simply pull the trigger, through a longer, heavier stroke. This causes levers and springs to both rotate the cylinder and draw the hammer to the rear, then release it, firing the cartridge. Firing a double-action revolver in single-action mode tends to be more accurate, because the trigger pull is much shorter and lighter; usually four or five pounds-force (18−22 newtons) of pull is sufficient, instead of the twelve to twenty pounds (50−90 N) required for double-action mode, so the firearm's aim is less likely to be disturbed by the force of pulling the trigger.
Self-loaders are firearms that use some of the discharge energy to reload the firearm. These are also called semi-automatics. These are typically fed from a tube or detachable magazine, commonly but incorrectly referred to as a “clip” (which correctly denotes a magazine reloading device used in certain rifles, or a retainer for flangeless bullets used in certain revolvers). The most well-known, American, semi-automatic rifle is the M-1 Garand, developed in 1919 at the Springfield Armory in Springfield, Massachusetts. After years of research and testing, the first production model of the M1 Garand was unveiled in 1937. During World War II, the M1 Garand gave American infantrymen an advantage over their opponents, most of whom were issued slower firing bolt-action rifles.
Automatics (also called full autos, machine guns, or machine pistols) were not practical until the development of smokeless powder in the late 19th century. Black powder caused too much fouling of the mechanism to allow automatics or self-loaders to be reliable. The Springfield-developed M14 rifle, considered the last "battle rifle," is an automatic. The M14 used by Americans soldiers during the Korean War and the Vietnam War.