A network with 65,000 addresses is too big to manage as one piece. So we cut it into smaller pieces called subnets. This lesson is about the cut: which part of the address names the network, which part names the machine, and how big each piece can be.
Difficulty: Beginner · Know this first: F14 — Private and Public IP Addresses
One network, 256 addresses, one piece. Nothing is cut yet. This is the starting point.
Subnet sizes are powers of two, and the differences are enormous. The bar below is exact: a /16 holds 65,536 addresses, a /24 holds 256, a /26 holds 64, and a /28 holds 16. The /16 is so big that the others are barely visible next to it. That is the point. Picking a size is picking a scale, and the scales are not close together.
Extra diagram · from scratch to master
Start with one flat network of 256 addresses. Cut it into four equal pieces and watch each piece get its own size and its own rules.
Extra diagram · from scratch to master
Start with one big VPC. Cut it into subnets, and mark each one public or private. The cut decides who the internet can reach.
The simulator below cuts a /24 network into equal pieces. Pick how many pieces you want, and it shows the new size, how many addresses each piece holds, how many hosts fit, and where the first piece starts and ends. Every number is computed live, and every number is exact.
The slider counts the bits taken from the host part: 0 bits means 1 piece, 2 bits means 4 pieces, 6 bits means 64 pieces. Each bit doubles the number of pieces and halves their size.
Try this: (1) Set the slider to 2 bits, which is 4 pieces. Each piece is a /26 with 64 addresses and 62 hosts, and the first piece runs from 192.168.1.0 to 192.168.1.63. (2) Set it to 4 bits, which is 16 pieces. Each piece is a /28 with 16 addresses and 14 hosts. (3) Set it to 6 bits, which is 64 pieces. Each piece is a /30 with 4 addresses and 2 hosts. The pieces get small fast.
Three questions. No score is saved anywhere — this is just you against the material.
I take the same idea four times here. First I split an address into two parts. Then I cut a network into pieces. Then I design the cuts for a whole organisation. Last I run it for the world.
Definition: Every IPv4 address has a network part, which names the network, and a host part, which names the machine inside it. The subnet mask says where the split sits. /24 means 24 network bits and 8 host bits, which gives 256 addresses.
Types:
Uses: I use this split every time I see an address with a slash after it. The slash number tells me the size, and the size tells me what the network is for.
Dimensions: At one network everything is one piece and the split never moves. What breaks first is my assumption that 256 addresses means 256 machines, and I notice it when the 255th machine has nowhere to go. It costs two addresses per subnet, the network and the broadcast. It costs real planning to remember the minus two. The trade is simple: the two reserved addresses buy a network that can name itself and talk to itself at once.
Definition: At this level I cut networks on purpose. A /24 becomes four /26 pieces, or sixteen /28 pieces. Each cut takes bits from the host part and gives them to the network part. Each piece gets its own boundary, its own rules, and its own purpose.
Types:
Uses: I use this when one flat network gets too noisy or too risky. The cut is the fix: smaller pieces, smaller blast radius, clearer rules about who may talk to whom.
Dimensions: As the pieces multiply, the planning matters more than the cutting. What breaks is a piece cut too small, and I notice it when the 15th guest arrives and there is no address left. It costs a size decision per piece, made before the piece is built. The trade is that small pieces buy isolation, and they cost addresses that sit empty in pieces that never fill.
Definition: At this level the cuts are a plan, not a reaction. One range per region, one piece per purpose, public and private subnets in every zone. The plan is written down, and every new network is cut from the plan, not improvised. Overlapping cuts are checked before anything is built.
Types:
Uses: I use this when a new environment is built. The plan fits on one page, and it saves the renumbering that follows an improvised cut. I check overlaps before I build, because fixing an overlap after is a week of work.
Dimensions: At ten times the networks the plan is the system, and the empty space is the most valuable part of it. What breaks is a plan with no room to grow, and I notice it when a new team needs a subnet and every piece is already full. It costs empty addresses held in reserve. The trade is that reserve space looks wasteful on paper, and it is the only thing that lets the network grow without renumbering.
Cut a /24 into four /26s. Splitting a network is arithmetic, not guesswork. A /24 holds 256 addresses. Cut it into /26s and you get four pieces of 64 addresses each. I do the split in code, because code does not make arithmetic mistakes at 2 in the morning.
$ python3 -c "
import ipaddress
net = ipaddress.ip_network('10.0.0.0/24')
print([str(s) for s in net.subnets(new_prefix=26)])"
['10.0.0.0/26', '10.0.0.64/26', '10.0.0.128/26', '10.0.0.192/26']
Every flag in the commands above, letter by letter.
python3 -c: -c means run the string that follows as code. The quotes hold the program. Without -c, python3 expects a filename.python3 -m runs a module by name. python3 -m json.tool reads JSON and prints it indented.Check it: run python3 -c "print(1+1)". It prints 2.
Try it: run the split above, then split the same /24 into /25s. You get two pieces, 10.0.0.0/25 and 10.0.0.128/25. The bigger the piece, the fewer pieces you get. Plan the split before you hand out addresses, because moving a machine to a new subnet later is real work.
The subnet that is too small. A /28 holds 14 usable addresses. A team of 20 machines does not fit in it. I count the hosts before I carve, because a subnet that runs out of addresses stops new machines from joining, and the fix is to renumber everything.
$ python3 -c "
import ipaddress
for p in [28, 27, 26, 25, 24]:
net = ipaddress.ip_network('10.0.0.0/' + str(p))
print('/' + str(p), 'hosts:', len(list(net.hosts())))"
/28 hosts: 14
/27 hosts: 30
/26 hosts: 62
/25 hosts: 126
/24 hosts: 254
Try it: run the count above. Each step down doubles the room. A /28 that needs 20 hosts is a plan that fails on day one. Pick the size for the team you will have in a year, not the team you have today.
Definition: At this level subnetting is a managed resource across regions, clouds, and teams. Every piece has an owner, a purpose, and a record. Cuts are reviewed before they are made. Overlaps are impossible by process, not by luck. And the plan is audited, because plans rot when nobody looks at them.
Types:
Uses: I use this when networks span regions and clouds. It is also how I review subnetting I did not build: I ask for the plan, I check the overlaps, and I look for the pieces nobody owns.
Dimensions: At a hundred times the scale the plan is the difference between a network that grows and a network that has to be rebuilt. What breaks is a cut made by hand outside the plan, and I notice it when two networks must join and their pieces overlap. It costs process: reviews, records, and audits. The trade is that process costs time up front, and it buys a network that can keep growing without ever stopping to renumber.
Growth breaks a tight plan. A subnet that fit the team last year does not fit the team this year. The fix is not to squeeze more machines in. The fix is to move to a bigger subnet, and that means new addresses for every machine on it. I leave one subnet empty when I plan, so growth has somewhere to go without renumbering.
$ python3 -c "
import ipaddress
net = ipaddress.ip_network('10.0.0.0/24')
subs = list(net.subnets(new_prefix=26))
print('total /26s:', len(subs))
print('use three, keep one spare:', [str(s) for s in subs[:3]], 'spare:', subs[3])"
total /26s: 4
use three, keep one spare: ['10.0.0.0/26', '10.0.0.64/26', '10.0.0.128/26'] spare: 10.0.0.192/26
Try it: run the split and pick which /26 stays spare. Write it down. When the team grows, the spare subnet is where the new machines go. A plan with no spare is a plan that breaks the first time it grows.
The mask is the cut. When someone says a network is 192.168.1.0/24, the /24 is doing the work. It says the first 24 bits are the network and the last 8 are the host. Without the mask, the address is just a number. With it, the address is a network with a size.
Powers of two are the whole arithmetic of subnetting. Every cut doubles the pieces and halves the size. That is why the sizes are 256, 128, 64, 32, 16, 8, 4, and never 100 or 50. If a size is not a power of two, it is not a subnet.
The minus two is the rule people forget most often, and it bites hardest on small subnets. A /30 has 4 addresses and 2 hosts. A /31 has 2 addresses and 0 hosts by the classic rule, which is why /31 is only used for links between two routers, where no host addresses are needed at all.
Broadcast is a feature, not a leftover. The last address in a subnet talks to every machine in it at once. Some services use it to find each other without knowing any addresses in advance. It is loud, which is why big flat networks suffer: one broadcast reaches everyone.
At 10x the subnets, the arithmetic stays easy and the bookkeeping gets hard. The cuts are simple. Remembering which piece is which, and who owns it, is the work. I write every cut down, with its purpose, the day it is made.
At 100x, the design changes. Subnets are cut by automation from a plan, and the plan is the source of truth. A human cutting by hand at that scale will overlap something. The automation checks the plan, and the plan is reviewed by a human. Both halves matter.
Try it: split your own /24. Run the split of 10.0.0.0/24 into /26s. You get four networks: 10.0.0.0, 10.0.0.64, 10.0.0.128, and 10.0.0.192. Each one holds 62 usable hosts. Assign one to servers, one to laptops, one to printers, and keep the fourth spare. That is a real subnet plan, and it took one command.
$ python3 -c "
import ipaddress
net = ipaddress.ip_network('10.0.0.0/24')
print([str(s) for s in net.subnets(new_prefix=26)])"
['10.0.0.0/26', '10.0.0.64/26', '10.0.0.128/26', '10.0.0.192/26']
A conference room filled up with guests for a training day, and the guest Wi-Fi stopped giving out addresses. The first 14 guests connected fine. The 15th got nothing. The guest subnet was a /28: 16 addresses, 14 hosts. Nobody had counted the guests against the size of the piece. The network was working exactly as designed. The design was too small.
Three things. First, the guest network stays a /24 from now on, because guests are the hardest group to count in advance. Second, every subnet gets a size note that says what it is for and how many it holds, so the next person can see the limit before the room fills. Third, a rule: size for the busy day, not the quiet one. A subnet that fits Tuesday will fail on training day, and training day is the day that matters.
Design the subnets for a small company VPC. The VPC is 10.0.0.0/16. You need web servers in two zones, databases in two zones, and room to grow. The web servers need about 40 addresses each. The databases need about 10 each. Plan the cuts.
The web subnets are /24 each: 10.0.1.0/24 and 10.0.2.0/24, one per zone, 254 hosts each, far more than 40 servers need. The database subnets are /28 each: 10.0.3.0/28 and 10.0.4.0/28, 14 hosts each, enough for 10 databases with room for a spare. The four subnets together use 544 addresses out of 65,536. The rest stays empty for growth, on purpose. If the web tier grows to 200 servers in one zone, the /24 still holds them, with 54 addresses to spare.
A /24 for the web tier buys room to grow and costs addresses that sit empty today. A /28 for the databases buys tight boundaries and costs the risk of outgrowing it, so I keep a spare /28 next to each one. Two zones buy survival and cost a second copy of everything. And the empty space in the /16 is not waste. It is the growth the company has not had yet.