How do switches and bridges learn where devices are located in a network?

Basically, when a frame enters a port the source MAC address is copied from the frame header.