How Does a Switch Learn Mac Addresses

  • How does a switch learn MAC addresses? It’s a core concept for anyone preparing for the CCNA exam. A switch is described as an intelligent device, but what exactly happens when it receives a frame?

    Let’s find out together by looking at a simple example.

    Step 1 – Topology Overview

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

    Figure 1 – Switch Learning MAC Addresses (Initial Topology)

    In the diagram above, we have three devices connected to a switch called SW1.
    Each device has a simplified MAC address:

    • PC1 → MAC address AAA

    • PC2 → MAC address BBB

    • PC3 → MAC address CCC

    To understand how the switch learns MAC addresses, let’s say PC1 wants to send a frame to PC3.

    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

    PC1 will create an Ethernet frame with:

    • Source MAC: AAA (its own address)

    • Destination MAC: CCC (the MAC address of PC3)

    When this frame arrives at the switch on port G0/1, the switch reads the Ethernet header and sees that MAC AAA was received on interface G0/1.

    Step 2 – MAC Address Table Check

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

    Figure 3 – MAC Address Table Check

    At this point, the switch checks its MAC address table.
    This table stores MAC addresses and the ports they are associated with.

    This table is basically a list that tells the switch:

    "This MAC address is connected to this port.”

    But for now, the table is empty the switch hasn’t learned anything yet !

    So what does it do?

    It reads the Ethernet frame sent by PC1 and looks at the source MAC address: it's AAA.
    And since it’s the first time the switch sees this MAC address, it says:

    “Okay, I don’t know this one yet… but I just received it on G0/1, so I’ll remember that!”

    So the switch adds an entry to its table:

    MAC address AAA → G0/1

    This is exactly how a switch learns MAC addresses: by associating the source MAC of incoming frames with the port they arrive on.

    This way the switch can learn mac address, the switch search the source mac address in the ethernet header and will verify if the switch already know it's address.

    The switch doesn’t need to be told where the devices are, it figures it out by looking at the source MAC address, that’s the key to understanding how does a switch learn MAC addresses dynamically.

    Step 3 – Source MAC Learned on G0/1

    How does a switch learn MAC addresses by saving the source MAC to the MAC address table

    Figure 4 – Source MAC Address AAA learned on G0/1

    But now the switch has to send the frame to its destination and that’s a different story.

    First the switch will checks its MAC address table again, this time looking for the destination MAC address which is CCC (that’s PC3).

    And here’s the problem:

    The switch doesn’t know yet where CCC is.
    There’s no entry for it in the table.

    So what does it do?

    Well, when a switch doesn’t know where to send a frame, it doesn’t guess it floods the frame.

    This means the switch will sends the frame out of all other ports except the one it came from.

    At that moment, the switch is basically saying:

    “I don’t know where CCC is, so I’ll ask everyone. Let’s see who replies.”

    Step 4 – Frame Flooding

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

    Figure 5 – Frame Flooding and Delivery

    At this point, both PC2 and PC3 receive the Ethernet frame.

    PC2 looks at the frame, checks the destination MAC address and thinks:

    “Hmm… this is for CCC, but my MAC address is BBB, not for me.”
    So PC2 just drops the frame.

    PC3 will respond because he sees that the destination MAC address in the frame matches his own.

    When PC3 replies, the new Ethernet frame will have:

    • Source MAC: CCC

    • Destination MAC: AAA

    Step 5 – Switch Learns the MAC Address of PC3

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

    Figure 6 – Switch Learns the MAC Address of PC3

    The switch receives this new frame on G0/3.

    It takes a look at the source MAC address which is CCC and thinks:

    “Alright, I don’t know this MAC yet… but I just got it on G0/3 let me save that in my MAC Address Table.”

    The switch adds a new entry to its MAC address table:

    MAC address CCC → G0/3

    Step 6 – Updated MAC Address Table

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

    Figure 7 – MAC Address Table

    Now the switch knows :

    • PC1 (AAA) is on Gi0/1

    • PC3 (CCC) is on Gi0/3

    So when the switch sees that the destination MAC address is AAA, it checks its table, finds that AAA is linked to G0/1.

    The Ethernet frame is forwarded to PC1 through that port.

    Step 7 – Frame Delivery

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

    Figure 8 – Frame Delivery

    What you need to remember is that the switch will remember the source MAC address and associate it with the port where it received the Ethernet frame.

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

    Answer the question below