I am having trouble understanding the steps in order to send an ip packet to another host on the same LAN. Most sources online that I have read and people I have talked to say that the host uses the subnet mask with the destination ip to determine if they are on the same subnet. I see how this works, but I have a few questions in regards to it.

In order to determine if it's on the same subnet, the host goes to the routing table, loops through each entry, and performs a bitwise AND on the entry's mask and the destination address of interest. This result is then compared with the same routing table entry's destination field. Whichever bits match the most throughout this process is determined as the best match. After finding the best match, it uses the entry's interface field to send out the datagram. If the best match entry has a gateway field that equals the IP of the sending host, then that tells the host that the destination of interest is on the same subnet. ARP is then used to find the MAC for the destination IP (if it isn't already in the ARP table) and the communication begins.

Is this correct? This is how it is described in TCP/IP illustrated. But yet when I talk to others and read online at some places, some people act like the host simply does a bitwise AND on the destination address with the host's subnet mask, and because that determines if it's on the same subnet, it then proceeds with ARP. That process doesn't involve the routing table at all.

Am I right in how I interpreted the author in TCP/IP illustrated or is the second approach I listed correct?

  • 1
    Everything goes through the routing table. Applications (i.e the OS) don't enumerate the interfaces to see if one is local; there will be a route in the route table for all "connected" networks.
    – Ricky
    Commented Oct 24, 2020 at 2:21
  • Is this a theoretical question, or is there a practical / implementation difference you are trying to tease out or take advantage of? Commented Oct 24, 2020 at 14:27

2 Answers 2


The routing table is always used to determine the next hop gateway. If the table is checked sequentially (in software), the entries are checked from the longest network mask/prefix length to the shortest.

Routing checks these entries until one matches the destination if (destination.ip & entry.mask) == (entry.ip & entry.mask) (& is the bit-wise and operation; also note that IP addresses are really 32-bit or 128-bit unsigned integers - the common notations are just for human readability). The result is a combination of gateway IP address and interface. If the gateway IP matches the interface address, the destination IP is local to that interface - effectively, the destination is its own gateway.

The packet is then sent to the determined gateway. If no match can be found, the packet can't be sent and it is dropped. Note that the default route matches any destination due to its zero-length mask.


Routing table always used in any scenario whether it is in same Lan or different networks . Routing table determine best path towards destination .

If destination is on that is same subnet

When traffic is intiàted from pc with souce ip address and destination are in same subnet or this process is determined by AND process by pc . If result from AND process find both source and destination and in same subnets or then packet will reach to layer2 switch and verifies mac -address table in layer2 switch bypassing verifying routing table..

If souce and destination are in different subnets

If both source and destination ip address belongs to different subnets than routing table in pc is verified that is persistent routes are verified packet is destined to gateway of souce ip adress futher packet will reach souce ip adress gateway with help of mac adress of gateway . From gateway packet will verify routing table in devices. if directly connected network means it will check ARP table and forwards packet to destination or els it will forward packet to next level according to routing table .

  • VLANs are irrelevant for routing decisions. They're just interfaces. Also, layer 2 is only used to pass the packet to the next hop. Persistence of routing entries is also irrelevant here.
    – Zac67
    Commented Nov 20, 2020 at 10:14
  • I have edited answers with respect to vlans . Persistence routes in PCs I am referring to .. Commented Nov 20, 2020 at 10:21

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.