It is amazing that anything is able to silence a gun, but gun silencers actually work on a very simple principle.
Imagine a balloon. If you pop a balloon with a pin, it will make a loud noise. But if you were to untie the end of the balloon and let the air out slowly, you could pop it making very little noise. That is the basic idea behind a gun silencer.
To fire a bullet from a gun, gunpowder is ignited behind the bullet. The gunpowder creates a high-pressure pulse of hot gas. The pressure of the gas forces the bullet down the barrel of the gun. When the bullet exits the end of the barrel, it is like uncorking a bottle. The pressure behind the bullet is immense, however -- on the order of 3,000 pounds per square inch (psi) -- so the POP that the gun makes as it is uncorked is extremely loud.
A silencer screws on to the end of the barrel and has a huge volume compared to the barrel (20 or 30 times greater). With the silencer in place, the pressurized gas behind the bullet has a big space to expand into. So the pressure of the hot gas falls significantly. When the bullet finally exits through the hole in the silencer, the pressure being uncorked is much, much lower -- perhaps 60 psi. Therefore, the sound of the gun firing is much softer.
Several alert readers have written to point out that a bullet that travels at supersonic speeds cannot be silenced because the bullet creates its own little sonic boom as it travels. Many high-powered loads travel at supersonic speeds. The silencer can remove the "uncorking" sound, but not the sound of the bullet's flight.