IP Basics - Routing 101

Workstations--To gateway or not to gateway
Every machine on your network with a TCP/IP stack has a configuration setting for gateway. This is so that it can reach IP networks other than its own. When it detects that the destination is part of a remote network, it sends the packet to the gateway for forwarding. For destinations in the same subnet, it will send the packet directly to the other machine. How does a workstation determine if a destination is part of the same or a different IP network?

First it ANDs the destination address of the packet with its own subnet mask. If the resulting address matches its own network mask, then the destination is in the same subnet, and the TCP/IP stack tells the card to send the packet directly to the destination machine. (Actually, more than this occurs in order to send the packet directly, but it's no longer part of TCP/IP, but Ethernet. This is covered in Section 2.2.) If, however, the calculation shows that the destination is part of another network, then the sender makes use of its gateway to transmit the packet. In effect, the sender is saying, "I do not know how to deliver this packet; can you please deliver it for me?" The gateway accepts the packet and then goes through a similar procedure. (That procedure is known as routing, and there will be plenty more about it later.)

Table 2.4: Address Information for Workstation Routing Examples

Here are a few examples of the workstation's decision-making process (the workstation IP and network information is in Table 2.4):

Workstation A sends to workstation B:
Workstation A knows its own network address/subnet mask is Workstation A calculates the local-subnettedness of the destination packet as follows:

Are A and B in the same subnet?


they are equal--both

Because the network address of the sender matches the result of this calculation, the packet is sent directly to machine B.

Workstation C sends to workstation B:
Workstation C knows its network address/subnet mask is Machine C checks to see if the destination packet falls within its subnet:

Are C and B in the same subnet?


they are not equal-- does not =

In this case, the comparison fails. The sender, C, has no choice but to send the packet to its gateway. (If you take the time to do the calculation, you discover the gateway is in machine C's subnet. In fact the gateway must always be in the sender's subnet; otherwise, the sender could not send to it either!)