Technically, ballistics is the science of how projectiles travel in flight. Forensic Ballistics is a misnomer since it doesn't concern itself with a projectile's flight but rather about analyzing the firearms used in crimes. Perhaps, ballistic fingerprinting is a slightly better term. Ballistics is actually a subset of the forensic science of Toolmark Analysis. Guns are a tool and ballistics experts study the marks left on bullets by the guns. I'll explain this as we go.
Bullets are made up of three components: primer, propellant (held in a cartridge) and the actual bullet.
The primer is a shock sensitive explosive – it will detonate if struck or if a spark occurs. The primer is kept in a tiny cup in the cartridge's head. The gun's hammer has a pin on it which directly strikes the primer. The detonation goes through a small hole in the cup and ignites the propellant. The explosion in the confined area forces the bullet out the barrel. By Newton's Third Law when the bullet explodes out the barrel, the cartridge must recoil backward. A piece of metal in the gun, called the breech, stops the cartridge from flying into the shooter's face.
Pause for a moment and realize that the hammer striking the cartridge will undoubtedly leave a mark and that you could most likely tell the gun manufacturer from this mark alone. Additionally, The breech will leave a mark on the head of the cartridge. Finally, an extractor will grab the cartridge and eject it also leaving another set of traceable markings. Back to the bullet:
The bullet is now cruising through the barrel. Back when guns were first invented, the projectiles would be very unstable and tumble in the air. This made them extremely imprecise. Rifling changed all this. The barrel of the gun is given a set of helix grooves. The heat from the gun powder causes the bullet to expand slightly. It expands into these grooves and then gets locked into the tracks. When the bullet comes out of the barrel it is spinning! Get it?
Why spinning? Because the spinning adds stability (and reduces air friction apparently). Consider a spinning top. It is very hard to knock off course compared to non-spinning top. We already discussed this when we talked about boomerangs.
But clearly, the grooves have dug into the bullet. By comparing the marks on a bullet found at a crime scene to a bullet fired from a confiscated gun, an expert can determine from these marks whether or not the bullet was fired from the suspected gun.
The data from ballistic forensics is not just class evidence but can also constitute individual evidence. Every time the bullet goes through the barrel it changes the rifling grooves, just as they change the bullet. The scratches and imperfections cause each ballistic fingerprint to be different.
There are a couple of things to be aware of:
Just because two bullets were fired from the same gun does not guarantee that the markings will match. Rust build up can change the stria or repeated firings of the gun will cause an evolution of the stria – imperfections in the bullet alter the groves in the barrel or the barrel of the gun could be replaced or purposely altered.
PS It seems fitting to add that if you want to read about Batman's relationship with guns rather than forensic ballistics you should check out the definitive post over at Silver Age Comics.