Inside a cylinder lock, there is a sort of puzzle, which only the correct key can solve. The main variation in lock designs is the nature of this puzzle. One of the most common puzzles is the pin-and-tumbler design, shown below.
The main components in the pin-and-tumbler design are a series of small pins of varying length. The pins are divided up into pairs. Each pair rests in a shaft running through the central cylinder plug and into the housing around the plug. Springs at the top of the shafts keep the pin pairs in position in the plug. When no key is inserted, the bottom pin in each pair is completely inside the plug, while the upper pin is halfway in the plug and halfway in the housing. The position of these upper pins keeps the plug from turning—the pins essentially bind the plug to the housing.
The correct key will push each pin pair up just enough so that the point where the two pins come together lines up perfectly with the space where the cylinder and the housing come together (this point is called the shear line). To put it another way, the key will push the pins up so that all of the upper pins are inserted completely in the housing, while all of the lower pins rest completely in the plug.