← All lessons
IP addressing and subnetting · Lesson 4 of 7

Splitting a network

Subnetting is cutting one network into smaller ones. You do it by borrowing bits from the host part and giving them to the network part. Each bit you borrow doubles the number of subnets and halves the size of each.

Say an office has 192.168.10.0/24 and wants four separate networks: staff, guests, cameras and servers. Four subnets need 2 bits (2² = 4), so the prefix grows from /24 to /26. Each /26 has 6 host bits left: 64 addresses, 62 hosts.

import ipaddress
net = ipaddress.ip_network("192.168.10.0/24")
for sub in net.subnets(new_prefix=26):
    print(sub)
Prints
192.168.10.0/26
192.168.10.64/26
192.168.10.128/26
192.168.10.192/26

Work from what you need. If each subnet needs room for 50 hosts, find the smallest host part that fits 50 + 2: 6 bits give 62 hosts, so each subnet is a /26. If you need 10 subnets, find the smallest number of borrowed bits that gives 10: 3 bits only give 8, so you need 4 (16 subnets).

Why bother? Smaller networks mean smaller broadcasts, and a router between them can apply rules: the guest Wi-Fi can reach the internet but not the office printers. You can also give different-sized subnets to different needs (VLSM), as long as they don't overlap.

Practice

You split a /24 into two equal subnets. What's the new prefix?

More info

Quick reference

Borrow n bits2ⁿ subnets, each half as big per bit.
Hosts neededSmallest h with 2ʰ - 2 ≥ hosts.
Subnets neededSmallest n with 2ⁿ ≥ subnets.
/24 → /26Four subnets of 62 hosts.
VLSMDifferent-sized subnets that don't overlap.

The other networking courses