Updated 1997 by PEG.
Updated 1992 by SIC.
Original by Robert Firth.
These are the props. You own a barn, 40 metres long, with automatic doors at either end, that can be opened and closed simultaneously by a switch. You also have a pole, 80 metres long, which of course won't fit in the barn.
Now someone takes the pole and tries to run (at nearly the speed of light) through the barn with the pole horizontal. Special relativity (SR) says that a moving object is contracted in the direction of motion: this is called the Lorentz contraction. So, if the pole is set in motion lengthwise, it will contract in the reference frame of a stationary observer.
You are that observer, sitting on the barn roof. You see the pole coming towards you, and it has contracted to a bit less than 40 metres, in your reference frame. (Does it actually look shorter to you? See Can You See the Lorentz-Fitzgerald Contraction? for the surprising answer. But in any case, you would measure its length as a bit less than 40 metres.)
So, as the pole passes through the barn, there is an instant when it is completely within the barn. At that instant, you close both doors simultaneously, with your switch. Of course, you open them again pretty quickly, but at least momentarily you had the contracted pole shut up in your barn. The runner emerges from the far door unscathed.
But consider the problem from the point of view of the runner. He will regard the pole as stationary, and the barn as approaching at high speed. In this reference frame, the pole is still 80 metres long, and the barn is less than 20 metres long. Surely the runner is in trouble if the doors close while he is inside. The pole is sure to get caught.
Does the pole get caught in the door or not? We can't have it both ways. This is the "Barn-pole paradox". The answer is buried in the misuse of the word "simultaneously" back in the first sentence of our story. In SR, events separated in space that are simultaneous in one frame of reference need not be simultaneous in another frame of reference. The closing of the two doors are two such events.
SR explains that the two doors are never closed at the same time in the runner's frame of reference. So there is always room for the pole. In fact, the Lorentz transformation for time is
t'=(t-vx/c2)/sqrt(1-v2/c2)
It's the vx term in the numerator that causes the mischief here. In the runner's frame, the more distant event (larger x) happened earlier than the closer event: the far door was closed first. It opens before he gets there, and the near door closes behind him. Safe again—either way you look at it, provided you remember that simultaneity is not a constant of physics.
If the doors are kept shut, the rod will certainly smash into the barn door at one end. If the door withstands this, the leading end of the rod will come to rest in the frame of reference of the stationary observer. There can be no such thing as a rigid rod in relativity, so the trailing end will not stop immediately, and the rod will be compressed beyond the amount that it was Lorentz contracted. If it does not explode under the strain and is sufficiently elastic, it will come to rest and start to spring back to its natural shape; but, since it is longer than the barn, its other end is now going to crash into the back door. The rod will then be trapped in a compressed state inside the barn.
References: Taylor and Wheeler's Spacetime Physics is the classic. Feynman's Lectures are interesting as well.