Say the switch table is empty. If computer A sends a frame destined to computer B, the switch will broadcast asking who has the mac address of B. What if C suddenly sends a frame to A? What is the mechanism so the switch doesn't mistakenly think computer C is computer B? Is it that it remembers the mac address of the destination desired by computer A, and when C tries to get to A it also contains its own mac address and the switch sees it isn't the same destination as computer A wanted?

Basically I'm asking, when a switch floods for an unknown mac address for a request sent by host A, how does it know that the destination is responding to host A or if some other host just happens to be transmitting to A?

  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can post and accept your own answer.
    – Ron Maupin
    Jan 3 at 1:31

Layer 2 switches (bridges) have a MAC address table that contains a MAC address and port number. Switches follow this simple algorithm for forwarding packets:

  1. When a frame is received, the switch compares the SOURCE MAC address to the MAC address table. If the SOURCE is unknown, the switch adds it to the table along with the port number the packet was received on. In this way, the switch learns the MAC address and port of every transmitting device.

  2. The switch then compares the DESTINATION MAC address with the table. If there is an entry, the switch forwards the frame out the associated port. If there is no entry, the switch sends the packet out all its ports, except the port that the frame was received on (Flooding).

Note that the switch does not learn the destination MAC until it receives a frame from that device.

  • Thank you @Ron for explaining it better. Now I know flooding is. The can also be found at en.wikipedia.org/wiki/Unicast_flood
    – Damon
    Nov 14 '14 at 15:31
  • This didn't answer the question I had asked.
    – Celeritas
    Nov 14 '14 at 22:37
  • 5
    @Celeritas Your assumption in your question is wrong. The switch doesn't "ask" who has a mac address. If it doesn't know the destination MAC, it floods the frame out all ports. It only learns source MACs when it receives a frame. So in your question, the switch can tell the difference between B and C because they have different source MAC addresses.
    – Ron Trunk
    Nov 14 '14 at 22:44
  • 4
    @Celeritas - The switch neither knows, nor cares, why any host is sending something to Host A. Why would it matter if a host is responding to Host A, or another host is sending something else to Host A? The switch only cares that the destination MAC is for Host A (and what the source MAC is if it isn't in the MAC address table). Only Host A cares if the received frame is a response from the host to which is originally sent a frame.
    – Ron Maupin
    Nov 14 '14 at 22:47
  • What Ron said, this concept is separate from ARP. Nov 14 '14 at 22:54

Your question presumes that the switch is involved in, or is aware of, the communication/conversation between two hosts (Is this a conversation between A and B or between A and C?). The switch isn't involved in the communication/conversation between two hosts. It simply knows (or learns) which MAC address is associated with which port and forwards (or switches) traffic destined for a particular MAC address to the associated port (once it has learned which port is associated with the MAC address), regardless of whether the source is B, or C or any other host connected to any other switch port.

Switches work at layer 2. Session management is the responsibility of higher layers.


Its not called switch table ; its MAC table. Now consider that MAC table is empty. When A tries to send a packet to B; the packet contains the MAC address of A and B. The switch updates MAC address of A in MAC table. Now since it doesn't know the port to which B is connected, so it broadcasts ARP packet at all of its ports and waits for all hosts to reply.

Now at the same time if C tries to send a packet to A, It extracts the MAC address of C from that packet and stores it in MAC table. Now since the MAC address of is already present in MAC table, so it knows to which port A is connected. Remember Data packets contains MAC address of both source and destination. Hence the MAC address of B & C are different. So the switch does not get confused. Now switch forwards the packet from C to A (Given that both are present in same VLAN).

To send the packet from A to B, it waits till B responds to ARP packet sent by switch. When it receives response from B, it updates the MAC address of B in its MAC table. Then finally the packet is forwarded to B.

Hence the switch does not get confused as the data packets (tcp/udp) contains both source and destination MAC address. And your switch won't forward a packet on an interface whose end host MAC address is not known to switch. It has to wait till the end host replies to ARP broadcast sent by switch.

  • 1
    This is not entirely accurate. A switch, unless it is a layer-3 switch, doesn't ARP. ARP is to resolve between layer-2 and layer-3, and the switch doesn't know layer-3. The switch does, indeed, broadcast a frame with an unknown destination MAC to every switch port. A host will ignore any frame with a destination MAC not its own.
    – Ron Maupin
    Nov 14 '14 at 13:19
  • 1
    And a slight clarification to Ron's clarification...mostly just terminology correction. When a switch sends a packet out to every port (except the ingress port) because it doesn't know where that particularly MAC address is located, its generally called "flooding". Nov 14 '14 at 14:42
  • @Ron thank you for your correction. A forgot to write that this is for layer 3 switch. And I also was like to admit that I forgot the term flooding, so I wrote the reply for layer 3 switches. And Jeff thank you for telling.
    – Damon
    Nov 14 '14 at 14:53
  • @Jeff McAdams, You are correct, it is flood, thank you. It was before my first cup of coffee after I got up early, and I meant broadcast in the language sense, not the network sense.
    – Ron Maupin
    Nov 14 '14 at 22:20
  • @Damon, that's what I didn't know is that every frame contains the source and destination MAC address.
    – Celeritas
    Nov 15 '14 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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