I have always wondered how a lock and key work. Now i got it :)
The common pin-and-tumbler locking mechanism has a series of spring-loaded pins, which are loaded into a series of small cylinders. Each cylinder has a bottom part, called a pin, and a top part, called a driver. Upon insertion of the key, the springs will be compressed as the key lifts the pin, pushing the driver into the upper chambers of the cylinder.
When the correct key is in the lock, the bottom and top pins align the space between them around a track similar to a ward, which is called the shear line.
When all of the pins and drivers are aligned to clear the way for the shear line, the key will turn. When the key is not in the lock, the pins should be at rest in the chamber, with the bottom pin in the key chamber and the top part of the pin resting on top of the bottom half due to the gentle pressure of the relaxed spring. An incorrect key will misalign one or more of the locking spring-loaded cylinders, blocking the key from turning by placing at least one of the pins or drivers in the way of the shear line.