IPv4 Routing Fundamentals: Connected Routes, Static Routes & Longest-Prefix Match Explained
BrainyTools Editor
Tech Contributor at BrainyTools

When a Cisco router's routing table has three matching routes for 10.1.1.1—a /16 OSPF route, a /24 RIP route, and a /26 static route—which path does the router pick, and in what exact order are Prefix Length, Administrative Distance, and Metric evaluated?
A Layer-3 router has one primary job: inspect the Destination IP address of each incoming packet, consult its IP Routing Table (show ip route), and forward the packet out of the interface that leads toward the destination network.
However, one of the most heavily tested topics on the Cisco CCNA (200-301) exam is the difference between:
- How a router builds its routing table when competing routing sources advertise the exact same prefix and mask (Administrative Distance and Metric), and
- How a router forwards a packet across the entries already installed in the routing table (Longest-Prefix Match, specified in IETF RFC 1812).
In this guide, we examine both mechanisms in detail and show you how to test longest-prefix matching in the Web Packet Tracer & Network Simulator.
1. Reading the Cisco IOS Routing Table (show ip route)
When you enable a router interface (no shutdown) with a valid IPv4 address and subnet mask, or configure a static route (ip route), the router populates its routing table:
R1# show ip route
Codes: C - connected, S - static
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
C 10.0.0.0/24 is directly connected, GigabitEthernet0/1
S 172.16.0.0/16 [1/0] via 10.0.0.2
S 172.16.10.0/24 [1/0] via 10.0.0.3
Standard Cisco IOS Route Source Codes
C(Connected): Automatically added when an interface is configured with an IP address/mask and reaches theup/upstate. Represents the entire subnet attached to that interface (e.g.,192.168.1.0/24).L(Local — IOS 15.0+): A/32host route added on modern Cisco IOS 15+ routers representing the exact IPv4 address assigned to the router's own interface (e.g.,192.168.1.1/32).S(Static): Manually configured by an administrator using theip route <network> <mask> <next-hop>command.S*(Candidate Default): A static default route (ip route 0.0.0.0 0.0.0.0 <next-hop>) used as the Gateway of Last Resort when no more-specific route matches.O(OSPF),D(EIGRP),R(RIP),B(BGP): Dynamic routing protocol entries.
What Does [1/0] Mean in a Routing Table Entry?
In the entry S 172.16.10.0/24 [1/0] via 10.0.0.3:
- The first number inside the brackets (
1) is the Administrative Distance (AD)—how trustworthy the routing source is (lower is more trusted). - The second number (
0) is the Metric—the cost calculated by that routing source to reach the destination network (static routes always have a metric of0).
2. Rule #1 of Packet Forwarding: Longest-Prefix Match Always Wins!
Per IETF RFC 1812 (Section 5.2.4.3), when a packet arrives at a router with a Destination IP (for example, 172.16.10.55), the router compares the destination IP against every route in the routing table (show ip route).
Suppose the routing table contains four matching routes that all include 172.16.10.55:
Route Entry in show ip route |
Matches 172.16.10.55? |
Prefix Length | Selected by Router? |
|---|---|---|---|
S* 0.0.0.0/0 [1/0] via 10.0.0.254 |
Yes (matches any IP) | /0 (0 bits) |
No |
D 172.16.0.0/16 [90/2816] via 10.0.0.10 |
Yes (172.16.x.x) |
/16 (16 bits) |
No |
O 172.16.10.0/24 [110/20] via 10.0.0.20 |
Yes (172.16.10.x) |
/24 (24 bits) |
No |
R 172.16.10.0/26 [120/4] via 10.0.0.30 |
Yes (.0 to .63) |
/26 (26 bits) |
YES! Longest Prefix (/26) Wins! |
Critical CCNA Exam Takeaway:
Notice that in the table above, the/26route was learned via RIP (AD = 120), while the/16route was learned via EIGRP (AD = 90) and the/24route via OSPF (AD = 110).
When forwarding a packet across routes that are already in the routing table, the router ONLY looks at Longest-Prefix Match (/26 > /24 > /16 > /0)!
Administrative Distance and Metric are only used beforehand when two routing protocols try to install the exact same prefix and prefix length (e.g., both OSPF and RIP advertise172.16.10.0/24with a/24mask) to decide which one gets placed into the routing table.
3. The 3-Step Route Selection Hierarchy (AD & Metric)
To keep the two concepts crystal clear for the CCNA exam:
- Longest-Prefix Match (Forwarding Time — Different Mask Lengths):
- Among routes already present in
show ip routethat match the destination IP, the route with the longest CIDR prefix (/32down to/0) is always chosen.
- Among routes already present in
- Administrative Distance (Control Plane — Same Prefix & Same Mask, Different Routing Sources):
- If two different routing sources advertise the identical network and mask (e.g., Static vs. OSPF both advertising
10.5.5.0/24), only the source with the lowest Administrative Distance is installed into the routing table.
- If two different routing sources advertise the identical network and mask (e.g., Static vs. OSPF both advertising
- Metric (Control Plane — Same Prefix, Same Mask, Same Routing Protocol):
- If a single routing protocol (such as OSPF) learns multiple paths to the identical network and mask (
10.5.5.0/24), it installs the path with the lowest Metric (or load-balances across equal-cost paths if metrics are tied).
- If a single routing protocol (such as OSPF) learns multiple paths to the identical network and mask (
Default Cisco IOS Administrative Distance Table (Must-Memorize for CCNA)
| Route Source | Default Administrative Distance (AD) |
|---|---|
Connected Interface (C) |
0 |
Static Route (S) |
1 |
| External BGP (eBGP) | 20 |
Internal EIGRP (D) |
90 |
OSPF (O) |
110 |
| IS-IS | 115 |
RIP (R) |
120 |
External EIGRP (D EX) |
170 |
| Internal BGP (iBGP) | 200 |
| Unknown / Unreachable (Never Installed) | 255 |
4. Hands-On Lab: Testing Longest-Prefix Match in Web Packet Tracer
You can verify longest-prefix routing in Router.ts using the Web Packet Tracer & Network Simulator:
- Open Web Packet Tracer and click Load Sample Topology.
- Click + Router (3p) twice to add
R2andR3, or useR1to test multiple overlapping static routes pointing to different next-hop IPs on10.0.0.0/24:- Suppose
R2is connected toSW2with IP10.0.0.2/24andR3is connected toSW2with IP10.0.0.3/24.
- Suppose
- On
R1, configure three static routes of increasing prefix specificity (0.0.0.0/0,172.16.0.0/16, and172.16.1.0/24):enable configure terminal ip route 0.0.0.0 0.0.0.0 10.0.0.2 ip route 172.16.0.0 255.255.0.0 10.0.0.2 ip route 172.16.1.0 255.255.255.0 10.0.0.3 end show ip route - Now run
ping 172.16.1.50vs.ping 172.16.2.50fromPC1in Step Mode and watch the Packet Trace Event Log:- Packet to
172.16.1.50matches/0,/16, and/24. Because/24is the longest prefix (24 > 16 > 0),R1ARPs for and forwards the packet to10.0.0.3(R3)! - Packet to
172.16.2.50matches/0and/16(it does not match172.16.1.0/24). Because/16is longer than/0,R1forwards the packet to10.0.0.2(R2).
- Packet to
5. Legitimate Sources & Standards References
- IETF RFC 1812: Requirements for IP Version 4 Routers (F. Baker, Ed., June 1995 — Section 5.2.4.3: Next Hop Address / Longest Match Prune).
- IETF RFC 4632: Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan (Section 5.1: Longest-Match Rule).
- Cisco IOS IP Routing: Protocol-Independent Configuration Guide: Administrative Distance default values and route selection rules.
- Cisco CCNA 200-301 Exam Topics (v1.1): Domain 3.0 IP Connectivity (3.1 Interpret the components of routing table: Prefix, Network mask, Next hop, Routing protocol code, Administrative distance, Metric, Gateway of last resort; 3.2 Determine how a router makes a forwarding decision by default: Longest prefix match, Administrative distance, Routing protocol metric).
6. CCNA 200-301 Exam Prep: Questions & Detailed Answers
Question 1
A router's routing table contains the following four entries:
O 10.10.0.0/16 [110/20] via 192.168.1.2D 10.10.8.0/22 [90/3072] via 192.168.1.3R 10.10.10.0/25 [120/3] via 192.168.1.4S* 0.0.0.0/0 [1/0] via 192.168.1.1
If the router receives a packet destined for 10.10.10.65, which next-hop IP address will the router forward the packet to?
- A.
192.168.1.1 - B.
192.168.1.2 - C.
192.168.1.3 - D.
192.168.1.4
Correct Answer: D
Explanation: This is a classic CCNA Longest-Prefix Match + Subnet Boundary question!
Let us check whether 10.10.10.65 actually falls inside 10.10.10.0/25:
- A
/25mask (255.255.255.128) covers addresses.0through.127in the 4th octet. - Since
65is between0and127,10.10.10.65does match10.10.10.0/25! - Even though
10.10.10.0/25was learned via RIP (AD = 120), it is already installed in the routing table and has the longest prefix (/25 > /22 > /16 > /0). Therefore, the router forwards the packet to192.168.1.4.
(Note: If the destination had been10.10.10.130, it would NOT match10.10.10.0/25, so it would fall back to10.10.8.0/22via192.168.1.3!)
Question 2
What are the default Cisco IOS Administrative Distance (AD) values for a Connected route, a Static route, an Internal EIGRP route, and an OSPF route?
- A. Connected:
0, Static:1, EIGRP:90, OSPF:110 - B. Connected:
1, Static:0, EIGRP:110, OSPF:90 - C. Connected:
0, Static:1, EIGRP:100, OSPF:120 - D. Connected:
0, Static:5, EIGRP:90, OSPF:110
Correct Answer: A
Explanation: By default on Cisco IOS, Connected = 0, Static = 1, Internal EIGRP = 90, OSPF = 110, and RIP = 120.
Question 3
A router learns about the exact same network prefix 172.16.50.0/24 from three different routing processes: OSPF (metric 10), RIPv2 (metric 2), and Internal EIGRP (metric 30720). Which route will be installed into the router's IP routing table?
- A. The RIPv2 route because it has the lowest metric (
2). - B. The OSPF route because its metric (
10) is lower than EIGRP's metric. - C. The Internal EIGRP route because it has the lowest Administrative Distance (
90). - D. All three routes will be installed for equal-cost load balancing.
Correct Answer: C
Explanation: Metrics from different routing protocols (RIP hop count vs. OSPF cost vs. EIGRP composite metric) cannot be compared directly. When multiple routing sources advertise the exact same prefix and prefix length (172.16.50.0/24), the router compares Administrative Distance: Internal EIGRP (90) beats OSPF (110) and RIP (120), so only the EIGRP route is installed into the routing table.
Question 4
How do you configure a Floating Static Route on a Cisco IOS router that acts only as a backup path if an OSPF route (AD = 110) to 10.20.0.0/16 disappears from the routing table?
- A. Configure a static route with an Administrative Distance greater than
110, such asip route 10.20.0.0 255.255.0.0 192.168.1.2 150. - B. Configure a static route with an Administrative Distance of
1. - C. Configure a static route with a
/15mask. - D. Configure the static route inside Interface Configuration mode.
Correct Answer: A
Explanation: A Floating Static Route is a static route configured with a manual Administrative Distance higher than the AD of the primary dynamic routing protocol. Since OSPF has a default AD of 110, configuring the static route with an AD of 150 (ip route 10.20.0.0 255.255.0.0 192.168.1.2 150) keeps it out of show ip route while the OSPF route is active, and automatically installs it if the OSPF route fails.
Question 5
What happens when a Cisco router receives an IPv4 packet destined for 198.51.100.25, no specific route in show ip route matches that destination, and Gateway of last resort is not set (no 0.0.0.0/0 default route exists)?
- A. The router floods the packet out of all active interfaces.
- B. The router drops the packet and sends an ICMP Destination Unreachable message back to the source IP address.
- C. The router holds the packet indefinitely in its ARP table.
- D. The router sends the packet back out of the ingress interface.
Correct Answer: B
Explanation: Unlike a Layer-2 switch (which floods unknown unicasts), a Layer-3 router never floods packets with unknown destination IPs. If no route matches in the routing table (and no 0.0.0.0/0 default route exists), the router drops the packet and generates an ICMP Type 3 (Destination Unreachable) message back to the sender.