Networking Fundamentals · Topic 4 of 5
Subnetting, Supernetting and Longest Match Routing
Learn how to subnet and summarize IPv4 prefixes, find network and broadcast addresses, and how longest match routing picks a route in Junos OS for JN0-106.
- 6 min
- Block size = 256 minus the mask value in the interesting octet.
- The network address is a multiple of the block size; the broadcast is one below the next network.
- Usable hosts = 2 to the power of host bits, minus 2.
What it is
Subnetting borrows host bits to split one network into several smaller subnets. Supernetting, also called summarization or aggregation, does the opposite: it combines several contiguous networks into one shorter prefix.
Longest match routing is the rule a router uses when more than one route covers a destination. It picks the route with the longest prefix, meaning the most specific one.
How it works
Subnetting step by step
Start with 192.168.10.0/24 and a need for four subnets.
- Bits to borrow: 2 bits give 2 to the power of 2 = 4 subnets. The new prefix is /26.
- Block size: 256 minus the mask octet. A /26 mask is 255.255.255.192, so the block is 256 - 192 = 64.
- List the subnets in steps of the block size.
| Subnet | Network | First host | Last host | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.10.0/26 | .1 | .62 | .63 |
| 2 | 192.168.10.64/26 | .65 | .126 | .127 |
| 3 | 192.168.10.128/26 | .129 | .190 | .191 |
| 4 | 192.168.10.192/26 | .193 | .254 | .255 |
Each subnet has 62 usable hosts.
Finding the subnet for a given address
Which subnet holds 172.16.45.200/20?
- A /20 mask is 255.255.240.0. The interesting octet is the third, with mask value 240.
- Block size is 256 - 240 = 16. Multiples of 16 in the third octet: 0, 16, 32, 48.
- 45 falls between 32 and 48, so the network is 172.16.32.0/20.
- The broadcast is one less than the next network: 172.16.47.255.
- Usable hosts: 172.16.32.1 to 172.16.47.254.
This block size method works for any octet and is the fastest way to answer exam questions without writing out all 32 bits.
Choosing a prefix for a host count
To fit a given number of hosts, find the smallest host bit count where 2 to the power of n, minus 2, is at least that number.
| Hosts needed | Host bits | Prefix |
|---|---|---|
| 2 | 2 | /30 |
| 25 | 5 | /27 |
| 50 | 6 | /26 |
| 100 | 7 | /25 |
| 500 | 9 | /23 |
Supernetting
Summarize 10.1.0.0/24, 10.1.1.0/24, 10.1.2.0/24 and 10.1.3.0/24:
- Write the third octets in binary: 0 =
00000000, 1 =00000001, 2 =00000010, 3 =00000011. - The first 6 bits are the same in all four, so the common bits are 8 + 8 + 6 = 22.
- The summary is 10.1.0.0/22.
A summary works cleanly only when the networks are contiguous and the first one starts on a block boundary. Four /24 networks starting at 10.1.1.0 cannot be summarized into a single /22.
In Junos OS, a summary route you build locally is an aggregate route:
user@router# set routing-options aggregate route 10.1.0.0/22
An aggregate route becomes active only when at least one more specific contributing route is in the routing table.
Longest match routing
A router compares the destination address with every route and keeps those whose prefix matches. Among them it chooses the one with the most matching bits. Route preference and metric only compare routes to the same prefix; they never override a longer match.
Routing table on a router:
| Route | Next hop |
|---|---|
| 0.0.0.0/0 | 203.0.113.1 |
| 10.0.0.0/8 | 10.255.0.1 |
| 10.1.1.0/24 | 10.255.1.1 |
| 10.1.1.64/26 | 10.255.2.1 |
- A packet to 10.1.1.70 matches all four; /26 is longest, so it goes to 10.255.2.1.
- A packet to 10.1.1.10 does not match the /26 (range .64 to .127); the /24 wins.
- A packet to 10.9.9.9 matches only /8 and /0; the /8 wins.
- A packet to 8.8.8.8 matches only the default route.
In Junos OS, show route 10.1.1.70 displays the most specific route that covers that address. Add exact to see only a route with exactly that prefix, for example show route 10.1.1.0/24 exact.
When a question lists routes with different preferences and prefix lengths, check prefix length first. A /26 static route beats a /24 OSPF route for an address inside the /26, whatever the preference values.
Common mistakes
Letting preference beat prefix length. Preference decides between routes to the same prefix from different sources. Longest match is applied first, across different prefixes.
Using the wrong block boundary. The network address must be a multiple of the block size in the interesting octet. 192.168.10.70/26 is not a network address; its network is 192.168.10.64.
Summarizing non-contiguous networks. A summary that covers addresses you do not own can attract traffic you cannot deliver.
The default route 0.0.0.0/0 has a prefix length of zero, so it is always the least specific match. It is used only when nothing else matches.
What to remember for the exam
- Block size = 256 minus the mask value in the interesting octet.
- The network address is a multiple of the block size; the broadcast is one below the next network.
- Usable hosts = 2 to the power of host bits, minus 2.
- Supernetting counts the common leading bits of contiguous networks.
- Junos builds summaries with
set routing-options aggregate route; the aggregate needs at least one contributing route. - Longest match wins first; preference and metric only break ties between routes to the same prefix.
show route addressshows the best matching route;exactlimits output to that exact prefix.
Check yourself
What are the network and broadcast addresses for 10.20.30.77/27?
Network 10.20.30.64 and broadcast 10.20.30.95, because the block size is 32.
Which single prefix summarizes 172.16.8.0/24 through 172.16.15.0/24?
172.16.8.0/21, because the eight networks share the first 21 bits.
A router has 10.0.0.0/8 with preference 5 and 10.1.0.0/16 with preference 10. Which is used for 10.1.2.3?
The 10.1.0.0/16 route, because longest match is applied before preference.
Topic 4 of 5 in Networking Fundamentals
Test yourself on Networking Fundamentals
The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.