How Does a Switch Learn Mac Addresses

  • A switch is called an intelligent device, but how does it actually learn which device is on which port?
    Let's find out with a simple example.

    Step 1 – Learn the Source MAC Address

    Topology diagram showing how a switch learns MAC addresses from connected devices

    Figure 1 – Switch Learning MAC Addresses (Initial Topology)

    In the diagram above, three devices are connected to switch SW1:

    • PC1 → MAC address AAA

    • PC2 → MAC address BBB

    • PC3 → MAC address CCC

    PC1 sends an Ethernet frame to PC3 with source MAC AAA and destination MAC CCC.

    Diagram showing how a switch learns MAC addresses by reading the source MAC from an Ethernet frame

    Figure 2 – Switch Learns the Source MAC Address

    To keep the focus on the switch, we assume PC1 already knows PC3's MAC address. How a device learns it is covered in the next lesson, on ARP.

    When this frame arrives on interface G0/1, the switch reads the source MAC address (AAA) and creates its first entry in the MAC address table: AAA → G0/1. A switch learns MAC addresses dynamically by associating incoming source addresses with their arrival ports.

    Answer the question below

    What is the source MAC in the first frame?

    On which interface does the switch learn MAC AAA?

    Step 2 – Flood the Unknown Destination

    Switch learns MAC address AAA on port G0/1 and updates its MAC address table

    Figure 3 – MAC Address Table Check

    The switch needs to forward the frame to destination CCC, but its MAC address table currently has no entry for it.

    How does a switch learn MAC addresses when destination is unknown by flooding the frame to all ports

    Figure 4 – Frame Flooding and Delivery

    When a destination is unknown, the switch floods the frame out of all ports except the one it arrived on (G0/1). Both PC2 and PC3 receive the frame. PC2 drops it because the destination MAC does not match BBB. PC3 accepts the frame and prepares a reply with source MAC CCC and destination MAC AAA.

    Step 3 – Learn the Reply and Forward

    Switch receives a new Ethernet frame with source MAC address CCC on port G0/3 and updates its MAC table

    Figure 5 – Switch Learns the MAC Address of PC3

    When PC3's reply arrives on interface G0/3, the switch reads source MAC CCC and adds a second entry to its table: CCC → G0/3.

    MAC address table updated with CCC on G0/3 as the switch continues to learn MAC addresses dynamically

    Figure 6 – MAC Address Table

    Now that the table contains both entries, the switch inspects the destination MAC (AAA), finds AAA → G0/1, and forwards the reply directly to PC1 without flooding.

    How a switch learns MAC addresses and forwards frames using its MAC address table

    Figure 7 – Frame Delivery

    Answer the question below

    Enter the flag you got from completing the scenario.

    Now let's take a look at some Cisco CLI commands to see how the switch builds its MAC address table in real time.

    Answer the question below

    True or false: a switch learns the destination MAC address from each frame.