Let's say we have a network like the one in the image below and the switches MAC tables are empty and the ARP tables are also empty. I want to send a packet from Host A to Host B. The question I want to ask is in what order and which MAC address the Switches learn?

Here is what i know till now:

Host 1 creates the packet with the Destination IP of Host B ( and sends it.

Switch 1 gets the packet and looks up in his MAC Table (its empty) and then sends it to all of his ports (flood) and in meanwhile saves up the Source MAC of Host A in his MAC Table.

The packet comes to the Router which sends it to Switch 2. Now does the Switch 2 learns (saves) the Host A MAC address (caz its the source MAC) or it learns the Router MAC from which the packet came and its port is connected?

Now the Switch 2 floods all ports and gets positive answer from Host B and learns(saves) his MAC address in his table. Now the process is going in reverse to Host A.

Switch 1 MAC Table:

Port------Source MAC

1------Host A MAC

5------Router's MAC or is it Host B MAC ?

Switch 2 MAC Table:

Port------Source MAC

1------Host A MAC or Router's MAC ?

3------Host B Netowrk

Thank you so much!

  • When thinking about these things it's helped me to think about big networks and efficiency. If the Mac was learned of every host from all other networks imagine the size these tables would get.
    – Fixitrod
    Aug 22, 2017 at 16:17
  • This article will explain how a switch populates its MAC address table. And this video will illustrate the process in conjunction with a router doing routing.
    – Eddie
    Aug 22, 2017 at 21:31

2 Answers 2


Each router replaces the Original source MAC address with the MAC adddress of the interface where the packet is going out of the router.

(in this case, the packet comes in through the red interface 
 and goes out on the brown interface).

So switch 2 and Host B learn the MAC address of the brown interface of the router.

They are unaware of the original MAC adddress, and they don't need to know it. When Host B needs to reply to Host Ait simply sends the packet to Host A IP address and Router's brown interface MAC.

  • Thank you so much, I understood clearly. I have one more question: Again lets say i need to send something from Host A to Host B and backwards. For every hop I need to write the MAC and IP address (if any) are in use.
    – Micky
    Aug 22, 2017 at 11:52
  • @Micky Yes. The IP address doesn't change unless there is NAT, but the MAC address change on each router hop.
    – jcbermu
    Aug 22, 2017 at 11:53
  • That's what I thought and the hops don't count on switches? The first hop on the pic above is on the router which means on the red interface and the second on is on the brown interface of the same router or just on the router as 1 and the next on is on the Host B which means total 2 hops? Is this correct Starts with: Source IP and MAC: Host A, Dest IP Host B, Dest Mac: Empty. Next hop is the Router: Source IP: Host A, Source MAC: Red interface, Dest IP Host B, Dest Mac: Brown Intefrace ?
    – Micky
    Aug 22, 2017 at 12:02

A router removes the frame around an incoming IP packet and encapsulates the packet with a new frame (depending on the layer 2 protocol) when passing it on.

The MAC tables of the switches are populated by ARP:

  1. When Host A is about to send a packet to Host B it queries its local routing table.
  2. The routing table indicates that Router is required as gateway to forward the packet.
  3. Router is connected by Ethernet, so its MAC address needs to be learned.
  4. Host A sends a (broadcast) ARP request for Router's IP.
  5. This propagates Host A's MAC address to all switches in the broadcast domain.
  6. Router responds with its MAC address, propagating its MAC address to the switches on the required path (when response is unicast) or on all switches (when response is broadcast).
  7. Host A learns Router's MAC address from the response
  8. Host A encapsulates the IP packet in an Ethernet II frame addressed to Router's MAC and transmits it.
  9. Router pretty much uses the same mechanism to forward the packet inside a new Ethernet frame to Host B.

To be exact, each switch removes the (layer 1) Ethernet packet around each (layer 2) frame on receipt and puts a new Ethernet packet around it when forwarding. So, layer 3 uses layer 2 for transport which in turn uses layer 1 for transport. Layer 1 is where the bits actually get moved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.