Different guns have different firing mechanisms. Bullets, however, generally work the same way. A modern bullet cartrige contains 5 parts:
1. The bullet itself (this is the part that actually shoots out of the barrel)
2. The case
3. The propellant, usually gunpowder
4. The rim
5. The primer
When you pull the trigger on a handgun, the hammer snaps forward and a pin strikes the primer(5). This creates a spark, which ignites the gunpowder(3), and the explosion propels the bullet(1) out of the gun. In a semi-automatic pistol the extractor then grabs hold of the rim(4) and ejects the empty casing from the gun to make room for the next round.