How does a switch learn MAC Addresses

This topic is to discuss the following lesson:

How does ComputerA know the mac address of ComputerB?

1 Like

Good question, take a look at this tutorial and you’ll find the answer:

I had read that tutorial before this one and I asked the question because we were working in layer 2 here (not using IP address)

Ah I see. The switch doesn’t care whatever is in the ethernet frame…only interesting thing for it are the source MAC addresses (to learn) and the destination MAC addresses (to forward).

What about when show mac add-table shows no mac for a port. But you know their is
a device on the other end

The switch won’t know a thing until it receives an incoming Ethernet frame, only then it can learn a MAC address. The good thing is that most devices always generate some traffic…just enable Wireshark for fun to see what a windows computer does on the background even though you are not actively running any programs.

But how computer A knows the MAC address of computer B. can you please help. I am confused.

This is a separate process that doesn’t have anything to do with the switch. The computers use ARP. You can read about it here:

Great lesson. Thanks for you showing this visual example and being clear in explaining the process!

You are welcome.

Hi Rene,

Great lesson.
I have faced some cases in the past that when I can connect a computer to the wall socket port and tried to generate some traffic from it even though the switch doesn’t show any mac address.

Please any help on this.


thank was informative

Hi Samir,

It’s difficult to tell what was wrong with your scenario. Normally any switch will start learning MAC addresses even without configuring anything…


Hi! Could you share me which app to draw the network diagram like in your website?

Wouldn’t the switch learn the MAC addresses during the ARP process, or even when the DHCP discovery happens?

Hi Callum,

On a real network, an ARP or DHCP discovery is probably the first packet that a computer sends on the network but it could be anything.


Any Ethernet frame received on a switchport will have its source MAC written to CAM for the VLAN on which the frame was received. This could be ARP or a DHCPDISCOVER message, it does not matter. It could be IPv6, IPX, or FCoE! Does not matter.

What if stations 2 and 3 switch ports? Entries in mac table for ports 2 and 3 become invalid. How does the switch correct this?

Good question, once you disconnect an interface the MAC addresses learned on that interface are flushed. Also, the default “aging time” is 300 seconds. That means that if there is no activity for that MAC address for 5 minutes then it will be flushed from the MAC address table.