Skip to content
Visual explainer 4h to learn 5 steps

Subnetting & CIDR

Compute network, broadcast, host range and host count for any CIDR prefix by hand.

By Invicly Tech, , in Computer Networking. About 9 minutes to read.

Topic 11 of 51

In short

Subnetting divides a network into smaller networks by borrowing host bits for the network part. CIDR notation such as 10.0.0.0/26 states how many bits are network bits. From the prefix you can work out the mask, network and broadcast addresses, usable host range and host count.

Explained simply

Subnetting means cutting one big network into several smaller ones. A company with the network 10.0.0.0/16 does not want all 65,000 possible devices in one giant broadcast domain. It cuts it into pieces: one subnet per floor, per department or per VLAN.

The number after the slash, the prefix length, controls the size. A bigger number means a smaller subnet. /24 holds 256 addresses, /25 holds 128, /26 holds 64, and so on: every extra bit halves the size.

Each subnet has a first address (the network address, which names the subnet) and a last address (the broadcast address, which reaches every host in it). Neither can be given to a device. Everything in between is usable: a /24 has 254 usable addresses, a /26 has 62.

With a little practice you can solve any subnet question in your head in under a minute. The trick is the block size: 256 minus the interesting number in the mask. Subnets always start on a multiple of the block size, so finding the right one becomes simple counting.

Press Play on a diagram to walk through it one step at a time.

FlowSolving 192.168.10.77/26
  1. 1
    Block size

    /26 leaves 6 host bits: 2^6 = 64.

  2. 2
    Mask

    255.255.255.192

  3. 3
    Network

    77 falls in 64-127: 192.168.10.64

  4. 4
    Broadcast

    192.168.10.127

  5. 5
    Usable hosts

    .65 to .126, 62 hosts

MapHalving 192.168.50.0/24 bit by bit
192.168.50.0/24 (256)
  • 192.168.50.0/25 (128)
    • 192.168.50.0/26 (64)
    • 192.168.50.64/26 (64)
  • 192.168.50.128/25 (128)
    • 192.168.50.128/26 (64)
    • 192.168.50.192/26: .192/27 and .224/27

In depth

The prefix-to-mask table you should memorise

A prefix length is just a count of 1 bits from the left. /24 is 24 ones, which is 255.255.255.0. Inside the last partly filled octet, the mask value depends on how many of its 8 bits are 1s: 1 bit = 128, 2 = 192, 3 = 224, 4 = 240, 5 = 248, 6 = 252, 7 = 254, 8 = 255.

So /26 is 255.255.255.192, /20 is 255.255.240.0 and /12 is 255.240.0.0. The total number of addresses is 2 to the power of the host bits (32 minus the prefix): a /20 has 12 host bits, so 4,096 addresses and 4,094 usable hosts. Knowing that /24 = 256, /16 = 65,536 and /8 = 16,777,216 lets you estimate any size quickly.

  • /25 .128 (128), /26 .192 (64), /27 .224 (32)
  • /28 .240 (16), /29 .248 (8), /30 .252 (4)
  • /31 .254 (2, point-to-point only), /32 .255 (1 host)
  • /20 = 255.255.240.0 = 4,096 addresses
  • /22 = 255.255.252.0 = 1,024 addresses

The block-size method, step by step

Find the interesting octet: the one where the mask is neither 255 nor 0. Subtract that mask value from 256 to get the block size. Subnets start at 0 and every multiple of the block size in that octet. Find the multiple at or just below the address's value: that is the network. The next multiple minus one is the broadcast. Octets to the left are copied; octets to the right become 0 for the network and 255 for the broadcast.

Example: 172.16.45.200/20. The mask is 255.255.240.0, so the third octet is interesting and the block is 256 - 240 = 16. Multiples of 16 around 45 are 32 and 48. Network: 172.16.32.0. Broadcast: 172.16.47.255. Hosts: 172.16.32.1 to 172.16.47.254, which is 4,094 hosts.

FlowSolving 172.16.45.200/20
  1. 1
    Mask

    /20 = 255.255.240.0; third octet is interesting

  2. 2
    Block size

    256 - 240 = 16

  3. 3
    Find multiple

    45 lies between 32 and 48

  4. 4
    Network

    172.16.32.0

  5. 5
    Broadcast

    172.16.47.255

  6. 6
    Hosts

    .32.1 to .47.254, 4,094 usable

Splitting a network into equal subnets

To split a network into N equal subnets, borrow enough bits that 2 to the power of borrowed bits is at least N. To make 6 subnets from 10.0.0.0/24 you need 3 bits (2 to the 3 = 8, since 2 bits only give 4), so each subnet is /27 with 32 addresses: 10.0.0.0, .32, .64, .96, .128, .160, .192 and .224. You get 8 subnets and keep 2 spare.

Work it the other way when you know the host count. For 500 hosts per subnet you need 9 host bits (512 - 2 = 510 usable), so each subnet is /23. From 10.0.0.0/16 that gives 128 subnets of /23: 10.0.0.0, 10.0.2.0, 10.0.4.0 and so on, each spanning two values of the third octet.

  • Subnets from borrowing b bits = 2^b
  • Usable hosts with h host bits = 2^h - 2
  • 6 subnets need 3 bits; 500 hosts need 9 host bits
  • A /23 spans two /24s: 10.0.4.0 to 10.0.5.255

Real-world details: wildcards, /31 and cloud subnets

Cisco ACLs and OSPF use wildcard masks, the inverse of the subnet mask: subtract each octet from 255. A /26 mask 255.255.255.192 has wildcard 0.0.0.63, and a /20 has 0.0.15.255. A 0 bit means must match, a 1 bit means any value.

The minus 2 rule has exceptions. A /31 has no network or broadcast address, so both addresses are usable on a point-to-point link (RFC 3021). A /32 identifies exactly one host and is used for loopbacks and host routes. Cloud platforms take more: AWS and Azure reserve 5 addresses in every subnet (the network address, the next three for the router, DNS and future use, and the last), so a /28 in AWS gives 11 usable addresses, not 14.

Learn it in 5 short steps

About 50m each. Track them with a timer in your plan.

  1. 1
    Convert prefixes to subnet masks~50m
  2. 2
    Find network and broadcast addresses~50m
  3. 3
    Count usable hosts per subnet~50m
  4. 4
    Split a network into equal subnets~50m
  5. 5
    Practise until under a minute each~50m

Key points

  • Usable hosts = 2^(32 - prefix) - 2 for prefixes up to /30.
  • Block size in the interesting octet = 256 - mask value.
  • Each extra prefix bit halves the subnet and doubles the subnet count.
  • A /24 split into four gives four /26 networks of 64 addresses each.

Key terms

Tap a card to flip it. 0/4 known

Examples

python
import ipaddress

net = ipaddress.ip_interface('192.168.10.77/26').network
print(net, net.netmask, net.broadcast_address, net.num_addresses - 2)
# 192.168.10.64/26 255.255.255.192 192.168.10.127 62
for sub in ipaddress.ip_network('10.0.0.0/24').subnets(new_prefix=26):
    print(sub)

Use code to check answers, but practise by hand until it is fast.

Solving a /27 in your head

Question: 10.40.7.99/27. Step 1: /27 means the last octet is interesting, with mask 224. Step 2: block size 256 - 224 = 32. Step 3: multiples of 32 are 0, 32, 64, 96, 128; 99 sits between 96 and 128. Step 4: network 10.40.7.96, broadcast 10.40.7.127. Step 5: hosts 10.40.7.97 to 10.40.7.126, which is 30 usable. Step 6: the gateway is usually the first host, 10.40.7.97. Check your answer with ipcalc.

bash
ipcalc 10.40.7.99/27
# Network:   10.40.7.96/27
# Broadcast: 10.40.7.127
# HostMin:   10.40.7.97
# HostMax:   10.40.7.126
# Hosts/Net: 30

Do these two hosts share a subnet?

Host A is 192.168.4.70/26 and host B is 192.168.4.130/26; they cannot ping each other directly. Step 1: block size is 64, so the subnets are .0, .64, .128 and .192. Step 2: A at .70 is in 192.168.4.64/26 (broadcast .127). Step 3: B at .130 is in 192.168.4.128/26. Step 4: different subnets, so they need a router between them. If someone set B to /24 by mistake, B would think A is local and ARP for it directly, while A sends replies to its gateway: a classic one-way mask problem.

Quick reference

  • Block size = 256 - mask value in the interesting octet
  • Addresses = 2^(32 - prefix); usable hosts = that minus 2 (up to /30)
  • /26 = .192 = 64; /27 = .224 = 32; /28 = .240 = 16; /29 = .248 = 8; /30 = .252 = 4
  • /20 = 255.255.240.0 (4,096); /22 = 255.255.252.0 (1,024); /23 = 255.255.254.0 (512)
  • Wildcard mask = 255.255.255.255 minus the subnet mask (/26 = 0.0.0.63)
  • /31 for point-to-point (2 usable), /32 for a single host
  • AWS and Azure reserve 5 addresses per subnet: a /24 gives 251 usable

Common mistakes

  • Forgetting to subtract the network and broadcast addresses.
  • Assigning the network address to a host.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1What is the broadcast address of 172.16.45.200/20?

Question 2

2You need at least 12 equal subnets from 10.1.0.0/16. What prefix do you use?

Question 3

3What is the smallest subnet that fits 120 hosts?

Question 4

4What is the wildcard mask for a /22?

Question 5

5Which address is a usable host in 192.168.9.0/29?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Find the network, broadcast, host range and host count for 192.168.200.37/28.

  2. Exercise 2medium

    Split 10.20.0.0/22 into 8 equal subnets and list each network address with its prefix.

  3. Exercise 3hard

    Write a bash script that takes an address and prefix (like 10.40.7.99 27) and prints the network and broadcast addresses using only shell arithmetic.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

What does CIDR mean?
Classless Inter-Domain Routing. It replaced the old fixed classes (A, B, C) with prefixes of any length, written as /n, so networks can be sized to fit.
Why subtract 2 from the host count?
The first address names the subnet and the last is its broadcast address, so neither can be assigned to a device. The exceptions are /31 and /32.
How do I get fast at subnetting?
Memorise the mask values (128 to 255) and their block sizes, then practise random questions daily. Most people get under a minute per question within a week or two.
Is 255.255.255.0 the same as /24?
Yes. The mask is just the prefix written out in dotted decimal: 24 one-bits followed by 8 zero-bits.

Go deeper

ShareXLinkedInWhatsApp