Gunpowder and invented in China, around 1200 years ago. They mixed sulfur and saltpeter, and immediately got to work exploding things with it.
The earliest gunpowder-based weapons were fire lances and fire cannons; fire cannons were held by hand, but otherwise worked similarly to later european cannons: Using explosions to shoot a metal ball really far.
Those same europeans also made hand cannons, which are smaller, more portable cousins of fire cannons.
That eventually evolved into the arquebus, similar in shape to modern rifles but supported by a hook.
All of these required the gunman to light the powder by hand, and didn't have a trigger to pull. By attaching a bit of flammable twine to a movable piece on the gun, we got matchlock guns.
Instead of igniting the gunpowder by hand, the gunman pulled the trigger, which moved a bit of string so that it set fire to the powder.
Matchlocks still weren't the most practical, so people experimented with the design. After trying out wheellocks, snaplocks, and snaphances, they arrived at the flintlock.
These have a similar idea, but use a bit of flint on a "hammer" instead of twine. Pulling the trigger makes the flint strike metal, causing a spark and igniting the powder. These are the guns used by pirates!
Flintlocks evolved into percussion cap guns, which had a primer on the gun instead of a flint on the hammer. And those evolved into modern cartridge guns!
Here, the primer is placed on the cartridges placed in the gun. Early cartridge guns were still single-shot, and needed to be reloaded after firing once. I'll go over further advanced in another post!
Here's other gun-related things that are useful to know!
Bullets & Cartridges
You feed your gun cartridges and bullets come out.
The bullet is a little metal thing that actually flies through the air. The cartridge includes both the bullet and other components, such as powder and primer.
Magazines & Clips
Many guns have magazines. The magazine holds the gun's cartridges. A clip holds several bullets to make loading a gun easier.
A magazine might be internal to the gun or detachable, and might be box-shaped, drum-shaped, or in other styles.
Many games and movies talk about gun types willy-nilly without explaining what they are exactly! So that'll be my first post.
Pistols
A "pistol" generally means any kind of handgun (i.e. a gun you can use with one hand). While movie and game characters often do just that, realistically you do want to hold them with both hands for accuracy. Some definitions exclude revolvers or derringers, but people generally include them in the definition.
Revolvers
Revolvers are guns with a cylinder that holds multiple cartridges. The cylinder revolves (spins) to fire each bullet in turn. While most revolvers are handguns, there's long guns too, such as revolver shotguns, rifles, and grenade launchers.
Rifles
What distinguishes a rifle is rifling — grooves cut into the barrel to make the gun more precise. The first rifles needed to be reloaded after each shot, but modern rifles can keep firing. Even fully automatic rifles are not designed to keep firing a lot though; they're made for firing in short bursts.
Machine Guns
A machine gun is a fully automatic rifled gun that is designed for sustained fire. Machine guns come in several varieties which are basically weight classes; a Light machine gun can be used by one person, a Medium machine gun is better used with a tripod and assistants, and a Heavy machine gun needs a weapon platform.
Submachine Guns (SMGs)
These are not considered machine guns proper; while they are also designed for continuous fire, SMGs use handgun-sized bullets instead of rifle-sized ones.
Shotguns
Shotguns are designed to fire shot: small pellets contained in a shell. This means they hit a broader area, and are easier to use. Shotgun barrels are generally smoothbore, with no grooves or cuts; this works better for firing shot, but worse for solid projectiles. Most shotguns can also fire slugs, big solid projectiles, for when you need.