To understand how a master key works, you must first have an idea of how locks work. The basis of each slot is generally the same. The most used lock in the world is the cylinder lock. That is why we take that as an example.
There are an inner and an outer cylinder in a lock. Pins prevent the cylinders from rotating. The moment you put the key in the lock, you push the pins upwards or downwards. This way you cancel the interruption. The cylinders can rotate and the lock opens. It is actually a kind of puzzle that only the key can solve.
But how does a master key fix this?
It is not the case that you can open every lock in the world with a master key. A master can only unlock a certain group of locks. Think for example of an apartment complex. A resident can only enter his home with the key, but a landlord must have access everywhere in case of emergency.
A lock is then designed to fit two keys. So the locks belonging to this group have two solutions to the puzzle: the pins can remove the lock from the lock in two positions and open the door.