The Phalanx CIWS (Close-In Weapon System) is a terminal defense
and cruise missile
s. Usually emplaced
on ships, it consists of a single 20mm M61A1 Gatling gun
married to a radar system and self-directing mount. It functions as follows: when incoming missiles are detected the system is armed. Its radar looks for any targets in its field of view that are moving towards the radar at measurable speed, and directs the mount to fire a stream of 20mm projectiles into the path of the incoming missile. The extremely high rate of fire of the M61A1 coupled with a fast enough compute
r means that the odds of at least one of these projectiles
hitting the incoming missile is substantial. Since cruise missile
s are fairly fragile, a hit will likely cause it to either detonate
into the water short of the ship.
These systems have a few shortcomings. One, they can only hold limited ammunition, so they are fairly easily saturated. Two, they aren't able to engage multiple targets at once. Three, they must be armed in good time; they aren't usually kept on because they have an unfortunate tendency to think, say, your own ship's helicopter is a perfectly good target. These flaws are slight, however, compared to the additional safety they provide the modern warship.
Trivia: They are sometimes referred to as 'R2D2' due to their shape (the radome is above the gun, and looks like a certain Star Wars character). There is a Dutch-designed similar system named Goalkeeper, produced by Signaal, that uses a GAU-8 rotary cannon, which is used on some NATO and other national ships (thanks locke baron for the correction!).
(some information from the U.S. Navy fact file)