When you build a cloud network, the first thing it asks is a range such as 10.0.0.0/16, and then a range for each subnet inside it. People find subnetting scary because of the binary maths in old textbooks. You can do the practical part with one idea and one small table, and you can check every answer with a short Python script. By the end of this lesson you will be able to read /24, size a network and split it into parts.
Why do we need it?
Every cloud network starts with address ranges. If you choose them badly, networks cannot be joined later, or you run out of addresses. Subnetting lets you separate public and private parts and apply different rules to each.
A real-life example
Imagine a block of flats with 256 doors numbered 0 to 255. You decide to give floors of 64 doors to different groups: floor one for offices, floor two for shops. That is subnetting: one big range split into smaller labelled parts.
What a subnet is
A subnet is a smaller network cut from a bigger one. Splitting a network has real benefits. Traffic stays inside its own part, you can apply different security rules to each part (for example one subnet for public web servers and another for private databases), and addresses are organised. In AWS, Azure and Google Cloud, this is exactly how you separate public and private resources.
The subnet mask and CIDR
An IPv4 address has 32 bits. Part of it identifies the network and the rest identifies the device inside that network. The subnet mask tells you where the split is. You will see it written two ways.
- As a dotted mask:
255.255.255.0. - As CIDR notation (Classless Inter-Domain Routing): a slash and a number,
/24. The number is how many bits belong to the network.
So 192.168.1.0/24 means: the first 24 bits (the first three numbers) are the network, and the last 8 bits are for devices. 8 bits give 2 to the power of 8 = 256 addresses. The more bits for the network, the fewer for devices, so a bigger slash number means a smaller network.
The one table you need
- /16 = 65,536 addresses. Mask 255.255.0.0. A common size for a whole cloud network.
- /24 = 256 addresses. Mask 255.255.255.0. A common size for a subnet.
- /25 = 128 addresses.
- /26 = 64 addresses.
- /27 = 32 addresses.
- /28 = 16 addresses.
- /30 = 4 addresses, used for links between two devices.
- /32 = 1 address, a single host.
The pattern: each time the slash number goes up by one, the number of addresses halves. The size is always 2 to the power of (32 minus the slash number).
Usable hosts
In a normal network, the first address is the network address (the name of the network itself) and the last is the broadcast address (to talk to everyone). Neither can be given to a device. So usable hosts equal total addresses minus 2. A /24 gives 254 usable addresses. Cloud providers reserve a few more in each subnet for their own use, which means a /24 subnet in AWS gives fewer than 254. Always check your provider’s documentation before you size a subnet tightly.
Check it with Python
Python has the ipaddress module in its standard library, which does the maths for you. This small script prints the details of any network and splits it into smaller ones. The script in this lesson was run on Linux in the course lab (bash 5, Python 3.13). The output shown is real. Your numbers (memory, disk, dates) will be different.
"""subnet.py - answer the usual CIDR questions with Python's standard library."""
import ipaddress, sys
net = ipaddress.ip_network(sys.argv[1] if len(sys.argv) > 1 else "10.0.0.0/24")
print(f"Network: {net.network_address}/{net.prefixlen}")
print(f"Netmask: {net.netmask}")
print(f"Broadcast: {net.broadcast_address}")
hosts = list(net.hosts())
print(f"Addresses: {net.num_addresses}")
print(f"Usable hosts: {len(hosts)} ({hosts[0]} to {hosts[-1]})" if hosts else "Usable hosts: 0")
print(f"Private: {net.is_private}")
if net.prefixlen < 30:
new_prefix = min(net.prefixlen + 2, 30)
print(f"\nSplit into /{new_prefix} subnets:")
for s in net.subnets(new_prefix=new_prefix):
print(f" {s}")
$ python3 subnet.py 10.0.0.0/24
Network: 10.0.0.0/24
Netmask: 255.255.255.0
Broadcast: 10.0.0.255
Addresses: 256
Usable hosts: 254 (10.0.0.1 to 10.0.0.254)
Private: True
Split into /26 subnets:
10.0.0.0/26
10.0.0.64/26
10.0.0.128/26
10.0.0.192/26
$ python3 subnet.py 192.168.1.0/26
Network: 192.168.1.0/26
Netmask: 255.255.255.192
Broadcast: 192.168.1.63
Addresses: 64
Usable hosts: 62 (192.168.1.1 to 192.168.1.62)
Private: True
Split into /28 subnets:
192.168.1.0/28
192.168.1.16/28
192.168.1.32/28
192.168.1.48/28
Splitting a network on paper
Say you have 10.0.0.0/24 and need four equal subnets. Four is 2 squared, so you add two bits to the network part: /24 becomes /26. Each /26 has 64 addresses, so the subnets start at 0, 64, 128 and 192: 10.0.0.0/26, 10.0.0.64/26, 10.0.0.128/26 and 10.0.0.192/26. That matches the output above. To check that an address belongs to a subnet, see whether it lies between the first and last address of the range.
Planning a cloud network
- Choose a private range for the whole network that does not overlap other networks you may join later, for example 10.0.0.0/16. Overlaps make it impossible to connect two networks.
- Split it into subnets by role: public, private application, and private database. Make one set in each availability zone.
- Give each subnet enough room to grow, but do not waste the whole range. A /24 or /20 is a common choice for a subnet.
- Write the plan in a table before you create anything.
Architecture diagram
Here is the idea as a simple picture. You can use the same diagram in your own notes.
flowchart TD
VPC[10.0.0.0/16 whole network] --> A[10.0.1.0/24 public subnet]
VPC --> B[10.0.2.0/24 private app subnet]
VPC --> C[10.0.3.0/24 private database subnet]
How to check it worked
- You can say how many addresses a /26 has without a calculator.
- You can explain why usable hosts are two fewer than the total.
- Your four subnet ranges do not overlap.
How companies use it
Cloud engineers split a /16 network into /24 subnets for web, application and database tiers in each availability zone. Firewalls and routes are applied per subnet. Overlapping ranges are a common cause of failed VPN and peering projects.
Common errors and how to fix them
- Ran out of addresses. The subnet was too small. Resize or add subnets, and remember providers reserve a few addresses.
- Overlapping ranges. Choose non-overlapping ranges for every network you may connect.
- Wrong mask in a config. Check the slash number matches the plan.
- Counting usable hosts wrongly. Subtract the network and broadcast addresses, and the provider reserved ones.
Best practices
- Plan ranges on paper first.
- Leave room to grow.
- Do not reuse ranges across networks that may connect.
- Use /24 or larger subnets for most tiers.
- Verify with a tool like the Python script.
Interview questions with simple answers
- What is a subnet? A smaller network carved out of a larger one.
- What does /24 mean? The first 24 bits are the network, leaving 8 bits (256 addresses) for hosts.
- How many hosts in a /26? 64 addresses, 62 usable.
- Why subtract 2? The network and broadcast addresses are not given to devices.
- What is CIDR? Notation that writes a network as address plus slash number.
- Why do cloud providers reserve addresses? For their own services such as the router and DNS.
- How to split a /24 into four? Make four /26 subnets.
- Why avoid overlapping ranges? Two overlapping networks cannot be joined.
- What is the netmask for /16? 255.255.0.0.
- Which range is private? 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16.
Practical exercises
Try each one yourself before you look at the hint. Struggling for a few minutes is how the skill sticks.
- Run the script on 172.16.0.0/20 and write down the usable hosts. Hint:
python3 subnet.py 172.16.0.0/20. - Plan a /16 with two /24 subnets in each of two zones. Hint: Four /24 blocks that do not overlap.
- Predict the number of addresses in /27, then check. Hint: 2 to the power of 5.
- Which of 10.0.1.5 and 10.0.2.5 is inside 10.0.1.0/24? Hint: Look at the third number.
- Split 192.168.10.0/24 into /28 subnets and count them. Hint: 16 subnets.
Mini project: Address plan
Make an address plan table for a small company with offices in two cities and a cloud network. No ranges may overlap. Check every range with the script.
Knowledge test
Answer the ten questions in the quiz at the end of this lesson. You pass with 60 percent. If an answer is wrong, read the explanation, then reread the part of the lesson it points to.