Answer provides the procedure to find the network address when a packet with destination IP( is reached at a router.

But a network packet has the destination IP in the IP packet but does not include /21. Router looks up the table of network prefixes with subnet mask(for ex:

Given a packet with destination IP( receiving at a router, How does a router determine its network address? to route the packet accordingly...

1 Answer 1


IP packets only have addresses, not masks or networks. An IPv4 address is simply a 32-bit number.

Routers have routing tables that consist of networks. A router will look for a routing table entry (network) that most closely matches the destination address of the IP address on the packet. If no possible match is found, the packet is discarded. If multiple matches are found, the longest match (most matched bits of the address and network) is used.

Some routers have default routes with the network. Every IPv4 network is a subnet of that network, so if there are no other (longer) matches, that route will be used, preventing any packets from being discarded.

A router will take the destination IP address, and it will compare it to the routing table entries for the mask length number of bits. If every bit of the destination address for the length of the routing table mask matches the routing table entry, then the router has a match.

  • Does router use the subnet mask of each network prefix and then perform the AND operation on received packet destination IP? Jan 10, 2019 at 15:33
  • Yes. That is how you determine the network of the address. The router looks to see if the destination address is in the network of any routing table entry, and the entry with the longest match wins.
    – Ron Maupin
    Jan 10, 2019 at 15:37
  • So... every table entry is (network_prefix_CIDR, next_hop_link), so router will forward the packet to next hop... Is that correct? Jan 10, 2019 at 15:38
  • Right. More advanced routers can do this in hardware using something like TCAM to greatly speed up the routing process over a software router.
    – Ron Maupin
    Jan 10, 2019 at 15:41
  • @overexchange, TCAM is a form of CAM that can use a mask. See this question for a better explanation of CAM and TCAM.
    – Ron Maupin
    Jan 10, 2019 at 15:43

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.