Routing Prefixes

Topics · Published 2019-08-05 · Revised 2026-11-23
Reviewed corrections applied locally; original wording preserved separately · Joomla source

8,556 Total views across this article’s versions; includes the historical baseline where available.

Additional, related information may be found in the following articles:

Routing Prefixes

An IPv4 routing prefix describes a destination range using a network address and a length from 0 to 32 bits. RFC 3222 discusses the terminology.[1]

For example, 192.168.10.0/24 fixes the first 24 bits and leaves eight bits free, covering 192.168.10.0 through 192.168.10.255. The address alone is not the complete prefix: /25 starting at the same address covers only the lower half of that range. See Slash Notation.

Why Are Routing Prefixes Important?

Prefixes let one route describe many destinations. Their lengths also make specificity precise: when several eligible routes match in the selected table, the route fixing the greatest number of destination bits wins. Linux uses specialized lookup structures rather than comparing the character lengths of command lines; see the kernel FIB documentation.

Linux Network Route Prioritization Logic

This article concerns IPv4 route selection in Linux. iproute2 is a collection of userspace administration tools; the kernel performs packet forwarding using the configured rules and routes.

Within a selected table, longest-prefix matching chooses the most specific eligible route. For equally specific alternatives, metrics and multipath configuration matter. There is no separate “highest bit” or longest-command-text tie-breaker.

Let’s walk through an illustrative example. Assume eth0 already has an address on 10.10.0.0/24, and the four gateway addresses below are reachable on that link. These additions assume the listed routes do not already exist. Our packet is addressed to 192.168.10.1.

ip route add default via 10.10.0.3 dev eth0
ip route add 192.168.10.0/24 via 10.10.0.4 dev eth0
ip route add 192.168.10.0/25 via 10.10.0.5 dev eth0
ip route add 192.168.10.1/32 via 10.10.0.6 dev eth0

The legacy route -n command could show the following illustrative rows in main, including the pre-existing connected route. Display order is unimportant; this is not captured output from a tested host.

Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.10.0.3 0.0.0.0 UG 0 0 0 eth0
10.10.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.10.0 10.10.0.4 255.255.255.0 UG 0 0 0 eth0
192.168.10.0 10.10.0.5 255.255.255.128 UG 0 0 0 eth0
192.168.10.1 10.10.0.6 255.255.255.255 UGH 0 0 0 eth0

Our destination matches /0, /24, /25, and /32. Which route wins?

The /32 route wins because all 32 destination bits match. It sends 192.168.10.1 through 10.10.0.6. The /25 fixes only 25 bits, the /24 fixes 24, and the default fixes none. Their command lines’ character lengths have no significance.

This example also distinguishes destinations within the same network:

  • 192.168.10.1 matches /32, so it uses 10.10.0.6.
  • 192.168.10.42 matches /25 but not /32, so it uses 10.10.0.5.
  • 192.168.10.200 matches /24 but not /25, so it uses 10.10.0.4.

These are calculated choices for the stated table, assuming no earlier policy rule changes the lookup and the next hops remain usable.

iproute2 Filtering Priority

The two ordering questions are different. Policy rules are examined by numeric priority; destination prefixes determine specificity inside a selected table. A successful lookup in an earlier table is not compared with a more specific route in a later table.

See Route Priority Processing and Follow the (ip) Rules for the surrounding policy model.

Endnotes

[1] Trotter, G. December 2001. RFC 3222: Terminology for Forwarding Information Base (FIB) based Router Performance. The Internet Engineering Task Force (IETF). The Internet Society. https://datatracker.ietf.org/doc/html/rfc3222.