Possible Duplicate:
How does Subnetting Work?

Imagine there is a small network with 2 subnets. Both of the subnets have their own switch (means: all machines on that subnet share the same switch). Both of the switches are connected to a router. The router is connected to the internet.

I want to understand the procedure of how a machine A in such a subnet contacts

  1. another machine B in the same subnet
  2. another machine C in the second (and therefore different) subnet
  3. another machine D on the internet

From what I unterstand:

In all 3 cases, machine A compares the target IP to its own subnet-mask. Now, machine A knows whether the target machine is located in the same (sub-)network or not. Is this correct so far?

If the target IP is located on the same (sub-)net, there is not much to do. Machine A just sends its data directly to machine B via the switch, there is no need for the router to intervene.

If the target IP is located in another (sub-)net, like machine C in the second subnet, machine A has no direct route. Therefore, it looks for its default-gateway (in this case the gateway is the router I think) and sends its data to the router. The router does some network address translation and delegates the data to machine C. I think it is the same procedue as for machine D on the internet.

I'm especially interested in how machine A knows whether to use the default-gateway/router or not. Is it just like I mentioned by comparing the target IP with the own subnet-mask? Or maybe I'm wrong here and it is not the job of machine A to determine that at all?

Thank you

marked as duplicate by Chopper3, Ward, mgorven, Ladadadada, petrus Aug 14 '12 at 21:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Read this; serverfault.com/a/49836/1435 - by the way this site is for professional sysadmins, your question is literally 'ABC' stuff, the most basic of basic - we're not hear to cover that ground. – Chopper3 Jun 24 '12 at 16:59
  • Set the proper subnet mask. – tftd Jun 24 '12 at 17:23

The answer above is perfect except:

  • The broadcast mentioned on line three is an ARP broadcast to the MAC FF:FF:FF:FF:FF:FF and will be received by all nodes within the collision domain unless the destination IP is found within the switches CAM table with a respective MAC of the destination node.

  • The broadcast will propagate to all nodes within the broadcast domain. The Broadcast Domain generally represents the local subnet. So sent on a network will be received by ip

  • WAIT! why not this address is used for directed broadcasts. Say im in the network but i want to communicate with all hosts. The I target the broadcast address of the subnet.

more examples broadcast address of usable address of - broadcast address of usable address of -


If the other machine is on the same subnet, it's determined from the netmask on the interface, so if it's not, then it's delivered to the default gateway. ARP plays a major role here as well, if it's the same subnet, it tries to get the MAC address via broadcast addr and if not, it does the same with the default gateway. So the packet is sent to the MAC of the default gateway, and there it goes up the same way until it's delivered to the destination. If e.g. core switch or any other switch with low-delay switching doesnt have the ARP of the destination machine yet it needs to forward the packet, it will forward it to all ports (normal switch would drop the packet), this is a small nuance here if you wonder how it works when there is no time to get the MAC address via ARP on core switch.

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