Subnets, Netmasks and Routing IP Packets

Pretend you are a router.  If you are at a certain IP and you have a certain destination IP to handle, do you send it to a router gateway, or can your computer talk directly with the destination?

Answer: XOR the destination with your IP and AND the result with the gateway mask, a zero result means you can talk to it directly.

Examples below assume I’m at looking to handle various IP addresses with a netmask of

send to myself: XOR IP> AND MASK> > available without router
send to a neighbor on my subnet: XOR IP > AND MASK > > available without router is correct
send to someone out of my subnet: XOR IP> AND MASK > > send to gateway is correct

notice the order is not reversible (yields a bad result)
Someone in my subnet: AND MASK > XOR IP> > send to gateway is the ~wrong~ answer.
In fact, ~all traffic will go to the gateway (wrong answer)
10.0.1.X AND MASK> > XOR IP > > send to gateway is the ~wrong~ answer.

Notice this logic can also be used to determine ~which~ gateway or route the packet is suppose to go to by ignoring your own IP address and comparing instead to possible destination gateways.  Evan Anderson does a fantastic and excruciatingly detailed writing on the topic of subnetting.  Download it to a pdf for your library.  However, it’s almost too detailed.  Summarizing his example 1/3 of the way down the page:

Destination is Options for routing include router #1 at and router #2 at XOR ROUTER 1 > AND MASK > – zero, yes use this router XOR ROUTER 2 > AND MASK > – nonzero, do not use this router


About Brian

Engineer. Aviator. Educator. Scientist.
This entry was posted in Computers. Bookmark the permalink.

Leave a Reply