Cisco IOS: Show ip route output order

cisco-commandscisco-ios-12

I am runing some BGP tests through the lab before rolling them out in production (thus, any IP addresses or AS numbers etc used here are done so in a completely fictitious manner).

Something that has always bugged me is the output on Cisco IOS of show ip route. What order are these routes in, it isn't numerical, 1, 2, 58 ,10! They aren't grouped by protocol , or metric either.

br2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 4 subnets
B       1.1.1.1 [200/0] via 10.10.0.1, 00:20:24
B       1.1.0.1 [200/0] via 10.10.0.1, 00:20:24
B       1.1.0.2 [20/0] via 10.20.0.1, 00:15:03
B       1.1.2.1 [200/0] via 10.10.0.1, 00:20:24
     2.0.0.0/32 is subnetted, 4 subnets
B       2.1.2.1 [20/0] via 10.100.0.1, 07:41:53
B       2.1.3.1 [20/0] via 10.200.0.1, 07:41:53
B       2.1.1.1 [20/0] via 10.100.0.1, 07:41:53
B       2.1.4.1 [20/0] via 10.200.0.1, 07:41:53
     58.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
B       58.58.58.2/32 [200/0] via 10.65.12.2, 00:20:25
S       58.58.58.0/24 is directly connected, Null0
B       58.58.58.1/32 [200/0] via 10.65.11.2, 00:20:26
     10.0.0.0/8 is variably subnetted, 15 subnets, 3 masks
i L2    10.10.0.0/30 [115/10] via 10.65.0.1, FastEthernet0/0
C       10.0.0.2/32 is directly connected, Loopback0
i L2    10.0.1.2/32 [115/30] via 10.65.0.1, FastEthernet0/0
i L2    10.0.0.1/32 [115/20] via 10.65.0.1, FastEthernet0/0
C       10.20.0.0/30 is directly connected, FastEthernet1/0
i L2    10.65.11.0/30 [115/20] via 10.65.0.1, FastEthernet0/0
i L2    10.65.13.0/30 [115/20] via 10.65.0.1, FastEthernet0/0
i L2    10.65.12.0/30 [115/20] via 10.65.0.1, FastEthernet0/0
i L2    10.65.1.0/28 [115/20] via 10.65.0.1, FastEthernet0/0
B       10.65.12.12/32 [200/0] via 10.65.12.2, 00:20:26
B       10.65.11.11/32 [200/0] via 10.65.11.2, 00:20:26
C       10.65.0.0/28 is directly connected, FastEthernet0/0
C       10.100.0.0/30 is directly connected, FastEthernet2/0.100
C       10.200.0.0/30 is directly connected, FastEthernet2/0.200
B       10.10.200.0/30 [20/0] via 10.200.0.1, 07:41:57
     60.0.0.0/32 is subnetted, 1 subnets
B       60.0.0.60 [200/0] via 10.65.13.2, 00:20:27

Even within the class-full boundaries or integer boundaries of prefix groups for example, 10.65.0.0/28 comes after 10.65.11.11/32.

Best Answer

They are in order of specificity; The most specific (longest network mask) is first, and the least specific (shortest netmask) is last. If the network is variably subnetted, then they are grouped with the least-specific of the various netmasks, and ordered most-specific-first in each of the groupings.

update

It seems the output of show ip route is in the order of the internal tree structure, rather than an explicitly ordered (in the sense of route selection order) listing.

For example, here's an old post from the Cisco forums; https://supportforums.cisco.com/thread/344940 regarding IOS 12.

(If anyone can write a more authoritative answer, please leave me a comment and I'll delete my answer.)