What Is Subnetting?#

Subnetting divides a large IP network into smaller, logical sub-networks. It’s one of the most fundamental skills in networking — every network engineer, cloud architect, and system administrator must understand it fluently.

Why Subnet?#

ReasonExplanation
Reduce broadcast domainsFewer hosts receiving every broadcast = less noise, better performance
Improve securityIsolate sensitive systems (databases, management) from general traffic
Efficient IP allocationDon’t waste a /16 (65,534 hosts) when you only need 30
Routing efficiencySmaller, summarizable networks reduce routing table size
Organizational structureMap network topology to departments, floors, functions

IP Address Structure#

An IPv4 address is 32 bits, written as four octets in dotted-decimal:

192.168.1.100
 ↓       ↓
Network  Host
portion  portion

The subnet mask determines where the network portion ends and the host portion begins.

Binary Representation#

IP:     192.168.1.100
Binary: 11000000.10101000.00000001.01100100

Mask:   255.255.255.0
Binary: 11111111.11111111.11111111.00000000
        ←——— Network (24 bits) ———→←Host→

The mask is always a contiguous block of 1s followed by a contiguous block of 0s. There are no gaps.


CIDR Notation (Classless Inter-Domain Routing)#

CIDR replaced the old classful system (Class A/B/C). The notation /n means the first n bits are the network portion:

192.168.1.0/24

/24 means:  11111111.11111111.11111111.00000000
            ←—— 24 bits = network ——→←8 = host→

CIDR Quick Reference#

CIDRSubnet MaskTotal IPsUsable HostsCommon Name
/32255.255.255.25510Host route
/31255.255.255.25422*Point-to-point link
/30255.255.255.25242Point-to-point
/29255.255.255.24886Tiny subnet
/28255.255.255.2401614Small subnet
/27255.255.255.2243230Small office
/26255.255.255.1926462Medium subnet
/25255.255.255.128128126Large subnet
/24255.255.255.0256254Standard LAN
/23255.255.254.0512510Large LAN
/22255.255.252.01,0241,022Campus
/21255.255.248.02,0482,046Large campus
/20255.255.240.04,0964,094Data center
/16255.255.0.065,53665,534Corporate
/8255.0.0.016,777,21616,777,214Large ISP

/31 is special: RFC 3021 allows point-to-point links with no network/broadcast address.

Formula#

Total addresses = 2^(32 - prefix)
Usable hosts    = 2^(32 - prefix) - 2   (subtract network address and broadcast)

Subnet Calculations (Step by Step)#

Given: 10.0.0.0/22 — What’s the range?#

Step 1: Determine host bits = 32 - 22 = 10 bits

Step 2: Total addresses = 2^10 = 1,024

Step 3: Network address = 10.0.0.0 (all host bits = 0)

Step 4: Broadcast address = last address = 10.0.3.255

10.0.0.0 in binary:    00001010.00000000.000000|00.00000000
                        ←——— 22 network bits —→←10 host bits→

Network:    00001010.00000000.000000|00.00000000 = 10.0.0.0
Broadcast:  00001010.00000000.000000|11.11111111 = 10.0.3.255
First host: 10.0.0.1
Last host:  10.0.3.254
Usable:     1,022 hosts

The “Magic Number” Shortcut#

For subnet calculations in the interesting octet:

Magic number = 256 - subnet mask value in that octet

Example: /22 → mask = 255.255.252.0

The “interesting octet” is the 3rd: 252

Magic number = 256 - 252 = 4

Subnets in 10.0.0.0/22 increment by 4 in the 3rd octet:

  • 10.0.0.0 – 10.0.3.255
  • 10.0.4.0 – 10.0.7.255
  • 10.0.8.0 – 10.0.11.255
  • …

Subnetting a Network (Dividing Into Smaller Subnets)#

Problem: You have 10.1.0.0/24 and need 4 subnets#

Step 1: How many bits to borrow? Need 4 subnets → 2^2 = 4, so borrow 2 bits

Step 2: New prefix = /24 + 2 = /26

Step 3: Each /26 has 2^6 = 64 addresses (62 usable hosts)

Result:

SubnetNetwork AddressFirst HostLast HostBroadcastUsable
110.1.0.0/2610.1.0.110.1.0.6210.1.0.6362
210.1.0.64/2610.1.0.6510.1.0.12610.1.0.12762
310.1.0.128/2610.1.0.12910.1.0.19010.1.0.19162
410.1.0.192/2610.1.0.19310.1.0.25410.1.0.25562

Finding the Subnet of a Given IP#

Problem: What subnet is 172.16.45.200/21 in?#

Step 1: /21 means the interesting octet is the 3rd (21 = 16 + 5, so 5 bits borrowed from 3rd octet)

Step 2: Mask in 3rd octet: 5 bits of network → 11111000 = 248

Step 3: Magic number = 256 - 248 = 8

Step 4: Subnets increment by 8: …40, 48, 56…

Step 5: 45 falls between 40 and 48, so:

  • Network: 172.16.40.0/21
  • Broadcast: 172.16.47.255
  • Range: 172.16.40.1 – 172.16.47.254

Verification in binary:

IP:     172.16.  00101|101  .200    (| marks network/host boundary)
Network: 172.16. 00101|000  .000  = 172.16.40.0
Broadcast: 172.16. 00101|111.255  = 172.16.47.255

VLSM (Variable Length Subnet Masking)#

VLSM allows subnets of different sizes within the same network — allocate exactly what each segment needs.

Problem: Allocate from 192.168.10.0/24#

SegmentHosts NeededSubnet Size
Server farm60/26 (62 usable)
Engineering28/27 (30 usable)
Sales12/28 (14 usable)
Point-to-point link 12/30 (2 usable)
Point-to-point link 22/30 (2 usable)

Rule: Allocate largest subnets first to avoid fragmentation.

Solution:#

SegmentSubnetRangeUsable
Server farm192.168.10.0/26.1 – .6262
Engineering192.168.10.64/27.65 – .9430
Sales192.168.10.96/28.97 – .11014
Link 1192.168.10.112/30.113 – .1142
Link 2192.168.10.116/30.117 – .1182
Remaining192.168.10.120/29 – .255Available for future—
flowchart LR
    A["192.168.10.0/24<br/>(256 addresses)"] --> B["/26<br/>Servers<br/>.0–.63"]
    A --> C["/27<br/>Engineering<br/>.64–.95"]
    A --> D["/28<br/>Sales<br/>.96–.111"]
    A --> E["/30<br/>Link 1<br/>.112–.115"]
    A --> F["/30<br/>Link 2<br/>.116–.119"]
    A --> G["Free<br/>.120–.255"]

Supernetting (Route Summarization / Aggregation)#

The reverse of subnetting — combine multiple smaller networks into one larger advertisement:

Problem: Summarize these routes#

192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24

Step 1: Write the 3rd octet in binary:

0: 00000000
1: 00000001
2: 00000010
3: 00000011
   ↑↑↑↑↑↑←— first 6 bits identical, last 2 differ

Step 2: Common bits = 24 - 2 = 22 bits → /22

Summary route: 192.168.0.0/22 (covers all four /24s)

When to Summarize#

  • At routing boundaries (between areas in OSPF, between ASes in BGP)
  • To reduce routing table size
  • Only works when networks are contiguous and properly aligned to power-of-2 boundaries

Private IP Ranges (RFC 1918)#

RangeCIDRAddressesTypical Use
10.0.0.0 – 10.255.255.25510.0.0.0/816.7MLarge enterprises, cloud VPCs
172.16.0.0 – 172.31.255.255172.16.0.0/121.05MMedium networks
192.168.0.0 – 192.168.255.255192.168.0.0/1665KHome/small office

Subnetting in Cloud (AWS VPCs)#

In AWS, subnetting is mandatory for VPC design:

flowchart TB
    VPC["VPC: 10.0.0.0/16<br/>(65,534 IPs)"] --> PubA["Public Subnet A<br/>10.0.1.0/24<br/>AZ us-east-1a"]
    VPC --> PubB["Public Subnet B<br/>10.0.2.0/24<br/>AZ us-east-1b"]
    VPC --> PrivA["Private Subnet A<br/>10.0.10.0/24<br/>AZ us-east-1a"]
    VPC --> PrivB["Private Subnet B<br/>10.0.11.0/24<br/>AZ us-east-1b"]
    VPC --> DBA["DB Subnet A<br/>10.0.20.0/24<br/>AZ us-east-1a"]
    VPC --> DBB["DB Subnet B<br/>10.0.21.0/24<br/>AZ us-east-1b"]

AWS reserves 5 IPs per subnet: network, VPC router (.1), DNS (.2), future use (.3), and broadcast.

So a /24 in AWS gives you 256 - 5 = 251 usable (not 254).


Practice Problems#

Problem 1#

Given: 172.20.0.0/16. Create 8 equal subnets.

Solution

Borrow 3 bits (2^3 = 8). New prefix: /19. Each has 2^13 = 8,192 addresses (8,190 usable).

#NetworkBroadcast
1172.20.0.0/19172.20.31.255
2172.20.32.0/19172.20.63.255
3172.20.64.0/19172.20.95.255
…increment by 32 in 3rd octet…
8172.20.224.0/19172.20.255.255

Problem 2#

Given: Host IP 10.50.172.88/20. Find the network, broadcast, and range.

Solution

/20: 3rd octet mask = 11110000 = 240. Magic number = 256 - 240 = 16.

172 ÷ 16 = 10.75 → floor = 10 × 16 = 160.

  • Network: 10.50.160.0/20
  • Broadcast: 10.50.175.255
  • First host: 10.50.160.1
  • Last host: 10.50.175.254
  • Usable: 4,094 hosts

Problem 3#

Given: Need subnets for: 500 hosts, 200 hosts, 50 hosts, 2 hosts. Use 10.10.0.0/22.

Solution

Sorted largest-first:

  • 500 hosts → /23 (510 usable): 10.10.0.0/23 (.0.1 – .1.254)
  • 200 hosts → /24 (254 usable): 10.10.2.0/24 (.2.1 – .2.254)
  • 50 hosts → /26 (62 usable): 10.10.3.0/26 (.3.1 – .3.62)
  • 2 hosts → /30 (2 usable): 10.10.3.64/30 (.3.65 – .3.66)
  • Remaining: 10.10.3.68 – 10.10.3.255

Total /22 = 1024 IPs. Used: 512 + 256 + 64 + 4 = 836. Remaining: 188.


Key Takeaways#

  1. The subnet mask splits network from host — it’s always a contiguous block of 1s
  2. Usable hosts = 2^(host bits) - 2 — subtract network address and broadcast
  3. The magic number shortcut (256 - mask) gives you the subnet increment
  4. VLSM enables efficient allocation — assign subnets sized to actual need, largest first
  5. Supernetting is the reverse — combine contiguous subnets into one summary route
  6. AWS reserves 5 IPs per subnet — plan accordingly (a /28 gives you only 11 usable, not 14)
  7. Binary is the source of truth — when confused, write it in binary and the answer becomes obvious
  8. Memorize the /24 to /30 range — these are used daily in real network design