This article covers a topic that is quite foundational to networking knowledge but, surprisingly, there has not been any previous articles on the subject on this site; so here goes.

In this article, we will consider how a Cisco router chooses which interface or next-hop address to forward a packet through/to. We will also look at classless/classful route forwarding.

CCNA Training – Resources (Intense)

Factors that Affect Route Selection

To begin this article, we need to familiarize ourselves with some concepts that affect how a router will select the best path to forward traffic through.

Administrative Distance

The first on the list is Administrative Distance. Administrative Distance talks about the trustworthiness of the source of a route. Just like you will believe news received from some news outlets more than others, in the same way a router will believe some route sources more than others. The lower the Administrative Distance, the more trustworthy the source of a route is.

The table below shows a list of the Administrative Distance for common route sources:

Source of route Default Administrative Distance




External BGP


Internal EIGRP




Although the Administrative Distance is a configurable value, most times we just leave the default values the way they are.


While Administrative Distance relates to several routing sources, metric has a scope within an individual routing source. A routing protocol that receives the same network information from multiple sources will rely on the metric to choose the best path – the lower the metric, the better the route.

Prefix length

Prefix length is just another way of representing the subnet mask. For example, is represented as /24.

How the Routing Table Is Built

Each routing process running on the router performs its own best path selection for every destination network it receives information about. For most routing protocols, the metric is used to determine the best path. For example, if a router running EIGRP receives two advertisements for the network, it will choose the path with the lowest metric as the best path.

Note: BGP uses a complex process to select the best path for a route. Also, there may be more than one best path, in which case load balancing may occur depending on the routing protocol.

After each routing process performs its internal best path selection process, it will attempt to install its best path route into the routing table. For the same route (same network, same prefix-length) that is attempted to be installed by multiple routing processes, the router will install the route from the source with the lowest Administrative Distance into the routing table.

With the routing table built, it then becomes easy for the router to forward traffic and it does this based on the longest prefix match.

Let’s use the lab setup below to explore this routing table building and route selection.

  • We will run EIGRP among R1, R2 and R3. Just to tip the balance a bit, we will change the default delay on R3’s e0/1 interface.
  • We will also run OSPF between R1 and R4.
  • We will configure a static route on R1 pointing towards R5 for the network.

Let’s begin with the network. R1 will receive information about that route from 3 routers: R2 and R3 (via EIGRP) and R4 (via OSPF).

We can check the EIGRP topology table on R1 to see the details about that route from R2 and R3.

Based on the metric (feasible distance), EIGRP has determined that the best path to reach that network is through, so it will attempt to install that route into the routing table.

Now, since that route is received from only one OSPF neighbor (, then that neighbor automatically becomes the best path. So the OSPF process will also try to install this route in the routing table.

To determine which one will be installed into the routing table, the router will use the Administrative Distance. Since EIGRP has a lower (better) Administrative Distance (90) than OSPF (110), the route from EIGRP will be installed into the routing table. We can confirm this by looking at that route in R1’s routing table:

Let’s take a look at the complete routing table of R1:

We see both the and networks in this routing table. Now the question is: If R1 wants to send traffic to, what next hop address will it forward the traffic to?

This is where longest prefix match comes in: even though falls under both and, the longer prefix is; therefore, R1 will forward the traffic to

We can confirm this by debugging IP packets on R1 and pinging

Hint: You can use an ACL to limit your debug to just ping traffic

R1#ping re 1
Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (1/1), round-trip min/avg/max = 1/1/1 ms
*Jul 2 14:03:23.582: IP: s= (local), d=, len 100, local feature
*Jul 2 14:03:23.582: ICMP type=8, code=0, Logical MN local(14), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSE
*Jul 2 14:03:23.582: FIBipv4-packet-proc: route packet from (local) src dst

*Jul 2 14:03:23.582: FIBfwd-proc: packet routed by adj to Ethernet0/1

*Jul 2 14:03:23.582: FIBipv4-packet-proc: packet routing succeeded
*Jul 2 14:03:23.582: IP: s= (local), d= (Ethernet0/1), len 100, sending
*Jul 2 14:03:23.582: ICMP type=8, code=0
*Jul 2 14:03:23.582: IP: s= (local), d= (Ethernet0/1), len 100, sending full packet
*Jul 2 14:03:23.582: ICMP type=8, code=0

On the other hand, if R1 receives a packet destined to, the longest prefix match for that packet is and so the next hop will be

IP Classless

While we are on this topic of route selection, it is a good time to discuss how the router behaves when the [no] ip classless command is configured. Although this command does not change the way the routing table is built, it affects the way packets are forwarded.

Starting from version 11.3, the default on Cisco IOS routers is that ip classless is enabled but we can disable it using the no ip classless command. When disabled, if a router has a supernet for a network in its routing table but receives a packet destined to an unknown subnet, that packet will be dropped EVEN IF a default route is present in the routing table.

An example will help drive home the point. Imagine a router with the following configuration:

ip route
ip route
ip route

The routing table of this router will look something like this:

Let’s consider a couple of scenarios with the default ip classless command configured. Remember that has a range of host IP addresses of to, while goes from to

  • If the router receives a packet destined to, it will forward it to because is the longest prefix match.
  • If the router receives a packet destined to, it will forward it to because is the longest prefix match.
  • If the router receives a packet destined to, it will forward it to because that destination does not match any other longer prefix so the default route will be used.

You can confirm that these results are true by debugging IP packets (detail) and sending one ping packet to those addresses from the router.

Now, if the no ip classless command is configured, the first two results will remain the same. However, the last result will change because the packet will be dropped. If you turn on IP packet debugging, you will get a message similar to the one below:

*Mar 1 00:01:13.059: IP: s= (local), d=, len 100, unroutable

The reason the packet is dropped is because the router knows the supernet (because it has some of the subnets of that supernet in its routing table), but since the router does not have the subnet that belongs to in its routing table, the packet is dropped even though there is a default route available.

However, for a packet destined to, say, the default route will be used because the router does not know about from any other source.


This brings us to the end of this article, where we have looked at route selection on Cisco routers. We covered several points like Administrative Distance, metric and prefix length. We also looked at how forwarding of packets is affected when the ip classless command is disabled.

I hope you have found this article insightful.

References and Further Reading