|MadSci Network: Chemistry|
It is a good party gag but a shameful waste of perfectly good beer. :( But quickly, the foaming over reaction is the same as when you shake up a beer or soda.
Beer and other carbonated beverages contain more carbon dioxide (CO2) than can naturally dissolve in a liquid/water (check out the second graph on this page for more info). Bottlers use a combination of low temperatures and high pressures to force the CO2 into the beverage, sealing the bottles as fast as possible. When you uncap a bottle, the excess carbonation wants to escape into the atmosphere. If the beer or soda is very cold and you are gentle with it, it won't foam over. If the beverage is only luke-warm, or is shaken or agitated, it will foam over just like you saw.
When you strike the bottle top with another
bottle, which I don't recommend because it is very easy to break the
bottle top and cut yourself, two things are happening: you are
(1) first increasing then decreasing the pressure inside the bottle very quickly; and
(2) agitating or shaking the liquid.
The bubbles that were trying to escape the liquid when you opened the beer, are being squashed/compressed with the sudden increase in pressure, making them more likely to combine with other small bubbles nearby. When the pressure is then released, these now-larger bubbles are going to rush to the surface of the liquid, causing it to foam. In addition, you've agitated the liquid by hitting the bottle, causing more bubbles to form and rush to the surface. Since the neck of the beer bottle is much more narrow than its body, the foam will go straight up and out, and you will lose a lot of beer in the process.
I hope this explanation has quenched your thirst for an answer, but again, I don't recommend this gag because of the risk of injury and ghastly loss of good beer.
Try the links in the MadSci Library for more information on Chemistry.