How switches learn MAC addresses
As you probably already know, each network card has a unique identifier called Media Access Control (MAC) address. MAC addresses are used in LANs for communication between devices on the same network segment. Devices that want to communicate need to know the MAC address of other device before sending out packets.
Switches also use MAC addresses to make accurate forwarding and filtering decision. When the switch receives a frame, it associates the media access control (MAC) address of the sending device with the interface on which it was received. The table that stores such associations is know as the MAC address table. This table is stored in the volatile memory, so associations will be erased after the switch is restarted.
To better understand how switches learn MAC addresses, consider the following example:
When SW1 is first powered on, the MAC address table will be empty:
But, when Host A sends a frame to Host B, the switch will add the HostA’s MAC address to its MAC address table, associating it with the interface Fa0/1. The switch will also learn the Host B’s MAC address when Host B responds to Host A and associate it with its interface Fa0/2: