During the age of cannon, captured guns would sometimes be disabled, so that if the enemy retook the position they could no longer defend it. Likewise, if you had to abandon a position, you might spike your own guns as you fled, so that the enemy couldn't use your own guns against you. A common way of doing this was to drive a metal spike into the cannon's touchhole. Once the touchhole was blocked, the cannon could no longer be fused and lit, and was useless in the short term. The cannon might later be rehabilitated by re-drilling the touchhole.
Troops would often carry hammers and spikes just for this purpose, and it was often an assigned role. Cavalry units were good at quickly riding around and spiking temporarily captured positions. Obviously, gunners were a good choice for manning the spikes in case of a hasty retreat abandoning the guns. They were also useful tools for a saboteur.
Ideally, spiking was done with a soft(er) metallic spike that could be flattened and deformed when hammered down, resulting in a top surface flush to the cannon, eliminating the possibility of prying it back out. Often, they were then pounded in a bit further using another piece of metal, putting the spike below the surface of the gun. While spikes were manufactured and deployed specifically for this use, nails, bayonets, and any other available and appropriately-shaped bits of metal might also be used.
As with any aspect of military technology, disabling a gun was given a lot of inventive thought, and where exactly spiking a gun ended and other forms of disabling started was hard to determine; for example, there are references to "spiking" a gun by hammering rocks or a 2-pound mortar repeatedly into the barrel of a gun to crack the barrel. Here is a short description of methods used to disable Civil War cannon from 1864:
"To spike a piece, or to render it unserviceable. Drive into the vent a jagged and hardened steel spike with a soft point, or a nail without a head; break it off flush with the outer surface, and clinch the point inside by means of the rammer. Wedge a shot in the bottom of the bore by wrapping it with felt, or by means of iron wedges, using the rammer or a bar of iron to drive them in; a wooden wedge would be easily burnt by means of a charcoal fire lighted with the aid of a bellows. Cause shells to burst in the bore of brass guns, or fire broken shot from them with high charges. Fill a piece with sand over the charge to burst it. Fire a piece against another, muzzle to muzzle, or the muzzle of one to the chase of the other. Light a fire under the chase of a brass gun, and strike on it with a sledge to bend it. Break off the trunions of iron guns; or burst them by firing with heavy charges and full of shot, at a high elevation. When guns are to be spiked temporarily, and are likely to be retaken, a spring spike is used, having a shoulder to prevent its being too easily extracted."
Artillery Drill: containing Instruction in the School of the Piece and Battery Manoeuvres by George Patten, 1864.
A spring spike is a variant type of spike, appearing in the 1790s, that is easily removed if you know the trick. It is a spike designed to have a bit spring out once it passes through the touchhole and enters the barrel, making it very difficult to remove -- unless you poke down the barrel with a ramrod to depress the spring.
As a sidenote, one of the more pleasing pieces of military statuary is a statue at Whitehaven Harbor, England, of American midshipman Joe Green spiking an English cannon. It commemorates the 1778 raid by US marine John Paul Jones on the (as it is currently known) Whitehaven Old Fort, in which a small contingency of 30 Americans and their European allies took the fort by stealth, disabled the guns, set a few ships on fire, and fled. This event brought the soon-to-be-famous American "pirate" John Paul Jones into the limelight of the British public.