The first locks that we know about were used by the Egyptians more than 4,000 years ago. They were made of wood, and were very large.
The Egyptian lock consisted of two pieces: a crossbar or bolt, and another piece of wood with a slot in it. This second piece of wood was attached to the doorpost, and the bolt fit into the slot when the door was locked. The bolt could not be pushed out of the slot because there were wooden pins in the slot that fit into holes in the bolt.
The key for this kind of lock looked like a huge toothbrush, with wooden pins instead of bristles. To open the lock, the Egyptians slid the key into an opening in the bolt.
The arrangement of the pins on the key exactly fit the holes in the bolt. So when the key was inserted in the bolt, the pins in the key pushed the slot pins out of the holes. Then the bolt was no longer held to the doorpost, and could be removed.
Only a key made especially for the lock would lift all the pins out of the bolt, so only that key could open the door!