Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I understand that in internet routers route packet from source host to destination host by using its network address, as it is not possible to maintain route tables for each IP address.

My question is how does the router separate out the network address from an IP address? Does an IP packet contain the network address also? or does it contain which class(A/B/C/D) does the IP address belong to etc?

share|improve this question

99% of the time routers on the internet are only looking at the destination IP address when routing packets over the internet. They first inspect the packets destination IP address and then perform a lookup in their routing table, they are looking for the most specific route that matches that IP address.

Routes are considered more specific if they have a longer network mask, in this example consider the router has these two routes within the local routing table. ( via ( via

If we received a packet with a destination address of we would use the more specific route (, this is more specific because of the net-mask been the maximum length 32 bits long. Therefore the packet would be routed out of our interface providing connectivity to the next hop

Where as a packet destined for would use it's most specific route, this isn't the best possible route for that subnet, just the best route we have at the moment. This packet would be routed out of the interface providing connectivity to the next hop address of

Finally it's worth noting that routing tables are generally built on the internet using a dynamic routing protocol called BGP, this will go through a long process of determining the 'best' route to install within the routing table, even before packets start to route.

share|improve this answer

Classes don't really exist anymore. Modern routers have, for each route, a network number and a subnet length. The packet only contains the destination IP address. The router routes the packet using the matching route with the longest subnet length. (Sometimes called the "longest prefix" or "most specific" matching route.)

This is explained well on the Wikipedia Longest prefix match page.

share|improve this answer

Full explanation can be found at howstuffworks Franklin, Curt. "How Routers Work" 31 July 2000.

Basically the router only needs to know whether a packet is local or remote. If it's local it delivers the package directly, if it's anything else it is delivered to another router the router itself is connected to and so on.

share|improve this answer
-1: it can't be that simple. Each router would need to be connected to at least two other routers, which begs the question, how do the routers decide which router to route a “remote” packet to? – Blacklight Shining Oct 15 '13 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .