Static Routing Explained: How Routers Forward Packets

Every packet on the internet needs directions. Static routes are the simplest way to tell a router where to send traffic.

Add your first static route

Free interactive lab. No signup. Runs in your browser.

Quick Summary

What Is Static Routing?

A router is a device that sits between networks and decides where to send each packet. When a packet arrives at a router, the router looks at the destination IP address and consults its routing table -- a list of known networks and where to forward traffic for each one. Static routing means a network administrator has manually typed each entry into that table, as opposed to dynamic routing protocols (like OSPF or BGP) which let routers discover routes automatically.

Think of static routing like a set of handwritten directions. You tell the router: "If a packet is headed for the 10.1.0.0/16 network, send it to the next router at 192.168.1.1." The router follows these directions exactly, without questioning or adapting. This simplicity is both a strength and a limitation -- static routes are easy to understand and configure, but they do not adjust if a link goes down or the network topology changes.

Static routing is ideal for small networks with predictable traffic patterns, stub networks with only one exit path, or lab environments where you want full control over every forwarding decision. In production environments, static routes often complement dynamic routing protocols -- for example, a default static route might point to an ISP gateway while internal routes are learned dynamically through OSPF.

The Routing Table

Every router maintains a routing table that maps destination network prefixes to next-hop addresses or exit interfaces. Each entry in the table has at least three pieces of information: the destination network (expressed in CIDR notation like 10.0.0.0/8), the next hop (the IP address of the next router that should handle the packet), and the exit interface (the physical or logical interface through which the packet should leave). Some entries also include a metric or administrative distance that helps the router choose between multiple possible routes to the same destination.

When a packet arrives, the router extracts the destination IP address from the packet header and compares it against every entry in the routing table. The router does not just look for an exact match -- it uses a process called longest prefix match. This means the router finds all routes whose network prefix covers the destination IP, then picks the one with the longest (most specific) prefix. For example, if the routing table has both 10.0.0.0/8 and 10.1.0.0/16, a packet destined for 10.1.5.3 would match both -- but the /16 route wins because it is more specific.

Interactive: Routing Table Lookup Simulator

Enter a destination IP address below and see which route the router selects using longest prefix match. Watch how the routing table highlights matching candidates and selects the winner.

Router R1 Routing Table

DestinationPrefix LenNext HopInterface
10.0.0.0/8/8192.168.1.1eth0
10.1.0.0/16/16192.168.1.2eth1
10.1.5.0/24/24192.168.1.3eth2
172.16.0.0/12/12192.168.1.4eth0
192.168.10.0/24/24192.168.1.5eth1
0.0.0.0/0/0192.168.1.254eth0

Packet Flow Through Multiple Routers

Click "Send Packet" to watch a packet travel from Host A through three routers to reach Host B. Each router consults its routing table and forwards the packet to the next hop.

Host A 10.0.0.5 Router 1 10.0.0.1 10.1.0.0/16 Router 2 10.1.0.1 10.1.5.0/24 Router 3 10.1.5.1 Host B 10.1.5.42 Packet PKT

How Longest Prefix Match Works

Longest prefix match is the algorithm routers use to select the best route from their routing table. When multiple routes overlap, the most specific one always wins. Here is why this matters: suppose your routing table has a route for 10.0.0.0/8 pointing to Router A, and a more specific route for 10.1.5.0/24 pointing to Router C. A packet destined for 10.1.5.42 matches both entries, but the /24 route is more specific -- it narrows the destination down to just 256 addresses instead of 16 million. The router will always choose the more precise instruction.

This hierarchical matching is what makes IP routing scalable. The internet's core routers can summarize huge blocks of addresses into short prefixes (like /8), while edge routers maintain more specific routes (like /24) for local subnets. Each router only needs enough detail to make the correct forwarding decision at its level.

1

Configuring a Static Route

On most routers, adding a static route is a single command. On a Cisco router you would type ip route 10.1.5.0 255.255.255.0 192.168.1.3, which tells the router: "To reach the 10.1.5.0/24 network, forward packets to 192.168.1.3." On Linux you would use ip route add 10.1.5.0/24 via 192.168.1.3. The syntax varies across platforms, but the concept is always the same: destination network, subnet mask, and next hop.

2

Default Routes

A default route is a special static route with destination 0.0.0.0/0. Because /0 is the shortest possible prefix, it matches every IP address -- but only when no more specific route exists. Default routes are the "catch-all" or "gateway of last resort." Most home routers have a single default route pointing to the ISP. Without a default route, any packet destined for an unknown network would be dropped with an "ICMP Destination Unreachable" message.

3

Administrative Distance

When a router learns the same route from multiple sources (static config, OSPF, BGP), it uses administrative distance to decide which one to trust. Static routes have an administrative distance of 1 by default, making them highly trusted. OSPF routes have distance 110, and BGP routes have distance 20 (eBGP) or 200 (iBGP). You can configure a static route with a higher distance to create a "floating static route" that only activates if the preferred dynamic route disappears.

4

When Static Routing Falls Short

Static routes do not adapt to changes. If a link fails, a static route pointing through that link will keep sending packets into a black hole until an administrator manually removes or updates it. In large networks with hundreds of routers and complex topologies, maintaining static routes is impractical. This is where dynamic routing protocols like OSPF, EIGRP, and BGP take over -- they automatically detect link failures and recalculate optimal paths.

Real-World Use Cases

Despite its limitations, static routing is everywhere. Here are three common scenarios:

🏠

Home Networks

Your home router has a single default static route pointing to your ISP's gateway. All traffic from your devices is forwarded to the ISP, which then uses dynamic routing to reach the destination. One route handles everything.

🔌

Stub Networks

A branch office with only one connection to headquarters does not need dynamic routing. A single default route at the branch and a static route at HQ pointing to the branch subnet is simple, reliable, and uses zero CPU for routing protocol processing.

🔬

Lab Environments

In networking labs, static routes give you precise control over packet paths, making it easy to test and debug specific topologies without the complexity of configuring OSPF or BGP. You can see exactly where every packet will go.

Common Static Routing Mistakes

Asymmetric Routing

You add a route from A to B but forget the return route from B to A. Packets reach their destination but replies have no path back. Always configure routes in both directions.

Routing Loops

Router A sends packets to Router B, which sends them back to Router A. The packet bounces forever until its TTL expires. Double-check next-hop addresses and test with traceroute before deploying.

Forgotten Default Route

Without a default route, any packet destined for a network not explicitly in the routing table is silently dropped. If internet connectivity is broken, the missing default route is the first thing to check.

Frequently asked questions about static routing

What is static routing?

Static routing is the practice of manually configuring entries in a router's routing table so it knows how to reach specific destinations. The routes do not change until an operator edits the configuration, which makes them simple but unable to react to topology changes on their own.

What is the difference between static and dynamic routing?

Static routes are entered by hand and remain fixed. Dynamic routing protocols like OSPF or BGP exchange information between routers and automatically rebuild paths when links fail. Static routing is predictable and costs the router almost no CPU; dynamic routing scales to large networks and recovers from outages without human intervention.

What is a default route?

A default route, written as 0.0.0.0/0, matches every destination the router does not have a more specific entry for. It is typically configured on edge routers to point at the upstream ISP so any unknown destination is forwarded toward the internet.

How does longest prefix match work?

When a packet arrives, the router compares its destination address against every prefix in the routing table and selects the entry with the longest matching prefix — that is, the most specific route. A /24 always wins over a /16 for the same network, which is why default routes are used last.

When should I use static routing?

Static routing fits small or stable topologies, stub networks with a single uplink, VPN endpoints, and labs. It is also useful as a backup or floating route alongside a dynamic protocol. For anything with multiple paths, frequent change, or many routers, prefer a dynamic protocol.

Try static routing

You just learned how routing tables, longest prefix match, and default routes drive every forwarding decision. Now build routers, add your own static routes, and trace each forwarding decision hop by hop. Press Go Live and the same routes are installed on real Linux routers.

Launch the routing lab →