IP Connectivity · Topic 2 of 5
How a Router Makes a Forwarding Decision
Learn the order a router uses to pick a route: longest prefix match first, then administrative distance, then metric, and how equal-cost paths are handled.
- 6 min
- Exam objective 3.2
- Longest prefix match comes first, and it overrides AD and metric.
- Administrative distance only matters when the prefix and mask are identical.
- Metric only matters between routes from the same routing protocol.
What it is
A router compares a packet's destination address with its routing table and picks one matching route.
Often several entries match, and the router must choose one. The choice follows a fixed order of tie-breakers, and learning that order is the key to answering most routing table questions.
How it works
The router applies three rules in a fixed order, and each rule is used only when the one before it leaves a tie.
The three rules, in order
| Step | Rule | What it compares |
|---|---|---|
| 1 | Longest prefix match | The most specific route wins |
| 2 | Administrative distance | The most trusted source wins |
| 3 | Metric | The best path within one protocol wins |
Step 1: longest prefix match
A route matches a destination if the destination falls inside the route's network.
The longest prefix is the match with the most bits, which means the most specific route. This rule always wins first.
Suppose the destination is 10.1.1.5 and the table contains:
- 10.0.0.0/8
- 10.1.0.0/16
- 10.1.1.0/24
- 0.0.0.0/0
All four match. The /24 is the longest, so the router uses it. A default route 0.0.0.0/0 matches everything, and since it has a length of zero it is always the last choice.
This rule ignores administrative distance and metric. A /24 route with a poor metric still beats a /16 route with an excellent metric, because specificity is checked first.
Prefix length is checked before administrative distance. A longer prefix wins even when it comes from a less trusted source.
Step 2: administrative distance
If two routes have exactly the same prefix and mask, learned from different sources, the one with the lower administrative distance wins.
For example, 192.168.5.0/24 may be known by OSPF (AD 110) and by a static route (AD 1). The router installs the static route. The OSPF route is held back as a backup, and it appears in the table only if the static route disappears.
AD only breaks a tie between routes with the same prefix length. It does not override a longer prefix.
Step 3: metric
If the same protocol offers several routes to the same prefix, the lowest metric wins. For OSPF, this means the lowest total cost.
If two routes from the same protocol have the same metric, the router can use both. This is called equal-cost load balancing, and the traffic is shared between the paths.
The number of equal-cost paths a router will use is limited. For OSPF and EIGRP, the default is four, and it can be changed with the maximum-paths command.
Putting it together
Consider these two entries.
S 192.168.5.0/24 [1/0] via 10.1.1.2
O 192.168.5.0/25 [110/20] via 10.1.2.2
A packet for 192.168.5.10 matches both entries, because the /25 covers addresses .0 to .127 and the /24 covers all of them. The /25 is longer, so it is chosen, even though the static route has a lower AD.
A packet for 192.168.5.200 matches only the /24 and goes through the static route.
What the router does next
Once the route is chosen, the router finds the outgoing interface and next hop.
- It looks up the next hop's MAC address, using ARP on an Ethernet link.
- It rewrites the Layer 2 frame header, with its own MAC address as the source and the next hop's as the destination.
- It decreases the TTL by one.
- If the TTL reaches zero, the packet is dropped and an ICMP message goes back to the sender.
If no route matches and there is no default route, the router drops the packet and sends an ICMP destination unreachable message.
Checking the decision
One command shows the route a destination would use.
show ip route 192.168.5.10
This displays the specific route that the router would use for that destination, and how it was learned. It is a quick way to test your own reasoning.
What to remember for the exam
Eight facts cover the forwarding decision.
- Longest prefix match comes first, and it overrides AD and metric.
- Administrative distance only matters when the prefix and mask are identical.
- Metric only matters between routes from the same routing protocol.
- A default route 0.0.0.0/0 is the least specific route and is used last.
- Equal-cost routes from the same protocol can be load balanced.
- The router rewrites the Layer 2 header and lowers the TTL at each hop.
- With no matching route and no default, the packet is dropped.
show ip route ADDRESSshows which route a destination would use.
Always work in the order prefix length, then AD, then metric. Never jump straight to the metric.
Common mistakes
These five errors are the usual ones.
Choosing by AD first. The prefix length is checked before the administrative distance. A longer prefix wins even from a less trusted source.
Comparing AD between different prefixes. AD only compares routes to the same prefix and mask.
Forgetting the default route is a match. 0.0.0.0/0 matches every address, but it is always chosen last.
Thinking a backup route is lost. A route with a higher AD is not deleted. It stays known and is installed if the better route disappears.
Calling any two routes equal cost. Equal-cost load balancing needs the same prefix, the same protocol and the same metric.
Check yourself
Work through these three prompts.
Which route does a router use for 10.1.1.5 when the table has 10.0.0.0/8, 10.1.0.0/16 and 10.1.1.0/24, and why?
It uses 10.1.1.0/24. All three routes match, and the /24 is the longest prefix, which makes it the most specific route.
When is administrative distance used, and when is it not?
It is used only to choose between routes with exactly the same prefix and mask that were learned from different sources. It never overrides a longer prefix.
What happens to a packet when no route matches and the router has no default route?
The router drops the packet and sends an ICMP destination unreachable message.
Topic 2 of 5 in IP Connectivity
Test yourself on IP Connectivity
The full Cisco CCNA 200-301 question bank has 1,206 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.