As keys age, they become brittle. At this point, it's possible for the key to break in half as you are unlocking a door, leaving part of it in the keyhole. This is especially common with older cabinets. You may initially think you need to remove the entire lock and replace it. However, there are a few things you can try before resorting to that.
Lubricate the inside of the lock around the broken key. Use a lubrication you can apply with a thin, flexible hose at the end of the can. Squirt the lubrication into the keyhole around the sides of the key. Tap on the lock to see if the key will wiggle out. If this does not work, move on to step 2.
Test the half of the key you have to see if it is magnetic. If it is, hold a magnet against a paper clip and insert the paper clip into the keyhole. The paper clip should attract the key so you can pull the key out of the keyhole. If this does not work, move on to step 3.
Apply a dot of super glue on the part of the key you have. Insert the key into the keyhole and press it firmly against the stuck half until the glue has dried. Then pull both parts of the key out of the keyhole. If this does not work, move on to step 4.
Insert either tweezers or needle nose pliers into the keyhole and try to get a hold of the broken key. If this does not work, you need to replace the lock.