How Routing Works
Routers forward packets between networks using a routing table
When a router receives a packet, it checks the destination IP against its routing table, finds the longest prefix match, and forwards the packet out the appropriate interface.
Longest Prefix Match: The most specific route (highest prefix length) always wins. /28 beats /24 beats /0.
Sample Routing Table (show ip route)
| Code | Network | AD/Metric | Next Hop / Interface |
| C | 192.168.1.0/24 | 0/0 | directly connected, Gi0/0 |
| L | 192.168.1.1/32 | 0/0 | local, Gi0/0 |
| S | 10.0.0.0/8 | 1/0 | via 192.168.1.254 |
| O | 172.16.0.0/16 | 110/2 | via 10.1.1.2, Gi0/1 |
| S* | 0.0.0.0/0 | 1/0 | via 209.165.200.2 |
C = Connected
L = Local
S = Static
O = OSPF
R = RIP
S* = Default route
Administrative Distance
Router's preference when multiple protocols know the same route
Lower AD = more trustworthy. If a route is learned by two different protocols, the one with the lower AD is installed in the routing table.
| Source | AD Value |
| Connected interface | 0 |
| Static route | 1 |
| EIGRP summary | 5 |
| OSPF | 110 |
| RIP | 120 |
| Unknown / Unreachable | 255 |
Floating static route: Set AD higher than the dynamic protocol (e.g. AD 115 for a static backup to an OSPF route). It only activates if OSPF fails.
Static Routing
Manually configured routes — no routing protocol needed
When to use: Stub networks (one path only), small topologies, default routes to the internet, or as backup routes.
Static Route Syntax
R1(config)# ip route network mask {next-hop-IP | exit-interface} [AD]
# Via next-hop IP (recommended)
R1(config)# ip route 10.0.0.0 255.0.0.0 192.168.1.254
# Via exit interface (point-to-point only)
R1(config)# ip route 10.0.0.0 255.0.0.0 GigabitEthernet0/1
# Default route (gateway of last resort)
R1(config)# ip route 0.0.0.0 0.0.0.0 209.165.200.2
# Floating static (AD=115, backup to OSPF)
R1(config)# ip route 10.0.0.0 255.0.0.0 192.168.1.254 115
OSPFv2 Concepts
Open Shortest Path First — link-state routing protocol
OSPF routers build a complete map of the network (LSDB) and use Dijkstra's SPF algorithm to calculate the shortest path. Metric = cost (reference BW ÷ interface BW).
OSPF Neighbor Adjacency States
Hello interval10s (broadcast) / 30s (NBMA)
Dead interval4× Hello (40s / 120s)
Reference BW100 Mbps (default)
Cost = 100,000,000 ÷ BW (bps)
DR/BDR electionHighest priority, then highest Router ID
Router ID priorityManual → Loopback → Highest active IP
Routing Table Lookup — Longest Prefix Match
How a router selects the best path for every packet
The router compares the destination IP against all entries and selects the most specific match (longest prefix). If no match exists the packet is dropped unless a default route (0.0.0.0/0) exists as the gateway of last resort.
Lookup order: Host route (/32) → Subnet route (/24) → Summary (/16) → Default (/0) → Drop
| Destination | Table Entry | Result | Reason |
| 10.1.1.5 | 10.1.1.0/24 | Best match | 24-bit match — most specific |
| 10.1.1.5 | 10.0.0.0/8 | Less specific | Used only if /24 absent |
| 192.168.5.1 | 0.0.0.0/0 | Default route | Gateway of last resort |
| 172.16.0.1 | (none) | Dropped | No match, no default |
Reading a Routing Table
R1# show ip route
Codes: C - connected, S - static, O - OSPF
[AD/metric] via next-hop, age, interface
O 10.1.2.0/24 [110/2] via 10.0.0.2, Gi0/1
S 0.0.0.0/0 [1/0] via 203.0.113.1
C 192.168.1.0/24 is directly connected, Gi0/0
Floating Static Routes
Backup routes that activate only when primary fails
A floating static route uses a higher AD than the primary so it stays hidden while the primary route exists. When the primary disappears the floating static automatically becomes active.
Primary (OSPF)AD 110 — active while OSPF neighbour is up
Floating staticAD 210 — hidden while OSPF route present
FailoverOSPF route drops → static becomes active immediately
Floating Static Config
! AD of 210 keeps this hidden behind OSPF (AD 110)
R1(config)# ip route 10.2.0.0 255.255.0.0 10.0.0.2 210
R1# show ip route 10.2.0.0
Route Summarisation
Aggregating multiple subnets into one advertisement
Summarisation reduces routing table size and limits OSPF LSA flooding. Convert all networks to binary, find the common left-most bits — their count is the summary prefix length.
172.16.0.0/24...00010000.00000000
172.16.1.0/24...00010000.00000001
172.16.2.0/24...00010000.00000010
172.16.3.0/24...00010000.00000011
Summary172.16.0.0/22 — 22 common bits
OSPF Summary on ABR
R1(config)# router ospf 1
R1(config-router)# area 1 range 172.16.0.0 255.255.252.0
OSPF LSA Types, Area Types & DR/BDR Election
The mechanisms behind OSPF topology distribution
OSPF uses Link-State Advertisements to share topology info. All routers in an area maintain identical LSDBs and run Dijkstra's SPF independently to find the shortest path.
LSA Types
Type 1 — Router LSAEvery router; describes its own links within area
Type 2 — Network LSADR-generated; multi-access segment members
Type 3 — Summary LSAABR-generated; inter-area routes
Type 4 — ASBR SummaryPath to ASBR
Type 5 — AS ExternalRedistributed external routes from ASBR
OSPF Area Types
Backbone (Area 0)All areas must connect here
Standard areaAccepts all LSA types (1–5)
Stub areaBlocks Type 5; injects default route
Totally stubbyBlocks Type 3, 4, 5; only default (Cisco)
NSSAAllows external via Type 7 LSA
DR/BDR Election
PurposeReduces flooding on multi-access segments
ElectionHighest priority (default 1) wins; tie = highest RID
Router IDHighest loopback IP, else highest active interface
DR multicast224.0.0.6 (DR/BDR); 224.0.0.5 (all OSPF)
DROtherForms full adjacency only with DR and BDR
OSPF Cost, Default Route & Router ID
R1(config-if)# ip ospf cost 10
R1(config-router)# auto-cost reference-bandwidth 1000
R1(config-router)# default-information originate always
R1(config-router)# router-id 1.1.1.1
R1# clear ip ospf process
R1# show ip ospf neighbor
R1# show ip ospf interface Gi0/0