This effect was made famous by the great Harry Houdini. Houdini often allowed himself to be locked in a jail cell completely naked and would emerge moments later free, fully dressed, and riding a bicycle. Today's male magician generally avoids the "naked" part of the effect, largely out of fear that the other inmates will find him "pretty."
The magician is searched, taken to prison, locked in a standard jail cell. All witnesses exit to another room, and the magician quickly escapes.
There is a wide variety of methods available for escaping from a jail cell. Some classic ones include:
Many other clever methods have been tried over the years. One -- used by one of those "naked" escaping magicians -- involved the magician sticking a foot in the cell door so that it could not close all the way. Another was to stand facing the bars, then turn 90 degrees (effectively making the magician thinner), and then just walk out between the bars sideways.