Subnets and IP ranges
Slicing the network, and planning addresses for growth.
Part 1: The problem
When Priya built QuickCart’s first network, she gave the VPC 10.0.0.0/24 — 256 addresses. It seemed like plenty for three servers.
Then QuickCart moved to containers. Every running container needs its own address, and the app subnets filled up in an afternoon. New containers failed to start with an error about no free addresses.
A subnet can’t be resized, and a VPC’s first range can’t be changed. The fix was a new, bigger VPC, and a weekend moving everything across.
Both problems come from choosing address ranges without a plan. This lesson is that plan: how to read a range, how big to make each one, and how to keep them apart.
Part 2: The idea
The VPC lesson showed that every range is written like 10.0.0.0/16, and that a smaller number after the slash means a bigger range. Here’s why.
An address is 32 bits
An IPv4 address like 10.0.11.24 is four numbers, each from 0 to 255. Each number is one octet: 8 bits. Four octets make 32 bits.
| Written | 10 | 0 | 11 | 24 |
|---|---|---|---|---|
| In bits | 00001010 | 00000000 | 00001011 | 00011000 |
A computer only sees the 32 bits. The dots are for people.
The slash says how many bits are fixed
In 10.0.0.0/16, the /16 means the first 16 bits are fixed. Every address in the range starts with the same 16 bits: 10.0. The other 16 bits are free: they can be anything.
Each free bit doubles the number of addresses. So the size of a range is 2 to the power of the free bits:
| Range | Fixed bits | Free bits | Addresses | Covers |
|---|---|---|---|---|
10.0.0.0/16 | 16 | 16 | 2¹⁶ = 65,536 | 10.0.0.0 to 10.0.255.255 |
10.0.0.0/20 | 20 | 12 | 2¹² = 4,096 | 10.0.0.0 to 10.0.15.255 |
10.0.1.0/24 | 24 | 8 | 2⁸ = 256 | 10.0.1.0 to 10.0.1.255 |
10.0.1.0/26 | 26 | 6 | 2⁶ = 64 | 10.0.1.0 to 10.0.1.63 |
10.0.1.0/28 | 28 | 4 | 2⁴ = 16 | 10.0.1.0 to 10.0.1.15 |
That’s the whole trick: free bits = 32 − the number after the slash; addresses = 2 to that power. One step down the slash doubles the size. One step up halves it.
Every block starts on its own boundary
A range is written as its first address. And a block of a given size can only start at a multiple of that size.
A /20 holds 4,096 addresses — 16 blocks of 256. So a /20 always starts where the third number is a multiple of 16:
| Valid /20 blocks in 10.0.0.0/16 | Not a valid /20 |
|---|---|
10.0.0.0/20, 10.0.16.0/20, 10.0.32.0/20, 10.0.48.0/20 | 10.0.1.0/20, 10.0.8.0/20, 10.0.20.0/20 |
The same rule at every size: a /24 starts at x.x.x.0, a /26 at .0, .64, .128 or .192, a /28 at a multiple of 16 in the last number. If a range doesn’t start on its boundary, the free bits wouldn’t all be free — some would already be set. AWS rejects it.
AWS keeps five addresses in every subnet
In every subnet, AWS reserves the first four addresses and the last one. For 10.0.11.0/24:
| Address | Reserved for |
|---|---|
10.0.11.0 | The network address — the name of the range itself |
10.0.11.1 | The VPC router, where traffic leaving the subnet goes first |
10.0.11.2 | The Amazon DNS server |
10.0.11.3 | Kept by AWS for future use |
10.0.11.255 | The last address. Networks use it for broadcast; AWS doesn’t support broadcast, so it simply keeps it |
So a /24 gives you 251 usable addresses, and the smallest subnet AWS allows, a /28, gives only 11. The five matter most in small subnets.
Which ranges to use at all
Three ranges are set aside for private networks. Nothing on the internet uses them, so they’re safe inside a VPC:
| Private range | Size | Notes |
|---|---|---|
10.0.0.0/8 | 16.7 million addresses | The usual choice. Room for 256 VPCs of /16 each |
172.16.0.0/12 | About 1 million | Default VPCs use 172.31.0.0/16 from here |
192.168.0.0/16 | 65,536 | Home routers use it. Avoid it, or your VPN users will clash with their own Wi-Fi |
A VPC can be anything from a /16 (65,536 addresses) down to a /28. Subnets have the same limits.
Planning for growth
A plan is cheap on paper and very expensive to change later. Three rules:
| Rule | Why |
|---|---|
| Give each VPC a /16 | Addresses inside a VPC are free. Running out is not |
| Make subnets bigger than today’s need, and leave most of the VPC unused | Containers and Kubernetes can use one address per running copy. You can add subnets later, but never resize one |
| Give every VPC its own range, even in another region or account | Overlapping VPCs can never be connected. 10.0.0.0/16, 10.1.0.0/16, 10.2.0.0/16… |
QuickCart’s plan for its first VPC, 10.0.0.0/16. The third number tells you the tier and the zone at a glance:
| Tier | Zone a | Zone b | Room to grow |
|---|---|---|---|
| Public | 10.0.1.0/24 | 10.0.2.0/24 | 10.0.3.0/24 for a third zone |
| App | 10.0.11.0/24 | 10.0.12.0/24 | 10.0.13.0/24 |
| Data | 10.0.21.0/24 | 10.0.22.0/24 | 10.0.23.0/24 |
| Containers, later | 10.0.32.0/20 | 10.0.48.0/20 | 4,091 usable addresses each |
Six subnets use 1,536 of 65,536 addresses. More than 95% of the VPC is left for things nobody has thought of yet. The second region gets 10.1.0.0/16 with the same layout, so the two can be joined whenever they need to be.
Part 3: See it
Below is QuickCart’s VPC, 10.0.0.0/16, drawn as a map: one square for every /24. Pick a size and a starting address, and add a subnet. Watch the bits, the address count, and the map. Then try to break it: start a /20 at 10.0.1.0, and add a /24 that lands on top of one that’s already there.
The VPC is 10.0.0.0/16. Type where a subnet starts, pick a size, and add it. Try 10.0.1.0 at /20 to see what goes wrong.
Subnets in the plan
What to notice: each step down in the slash doubles the addresses and halves the number of blocks that fit. A block only fits where its fixed bits line up, and nothing may overlap — the two rules AWS enforces every time you create a subnet.
Part 4: Do it
Free — VPCs and subnets cost nothing.
You’ll plan QuickCart’s addresses on paper, build part of the plan, and deliberately hit the two errors from this lesson so you recognise them. About 20 minutes.
Check the region selector at the top right of the console says N. Virginia (us-east-1).
Plan on paper first
Before opening the console, write down the plan from the idea: one VPC, and a public, app and data subnet in each of two zones. For each subnet, work out:
Subnet Range Addresses Usable First usable Last usable quickcart-public-a10.0.1.0/24256 251 10.0.1.410.0.1.254quickcart-app-a10.0.11.0/24256 251 10.0.11.410.0.11.254quickcart-data-a10.0.21.0/24256 251 10.0.21.410.0.21.254Fill in the zone b rows yourself —
10.0.2.0/24,10.0.12.0/24and10.0.22.0/24— and check your answers with the planner above.You should seeA table where no two ranges share an address, every range is inside
10.0.0.0/16, and most of the VPC is still unused.Create the VPC
In the AWS console: VPCYour VPCsCreate VPC
Field Enter Resources to create VPC only Name tag quickcart-vpcIPv4 CIDR block IPv4 CIDR manual input IPv4 CIDR 10.0.0.0/16IPv6 CIDR block No IPv6 CIDR block Tenancy Default Choose Create VPC.
You should seeThe VPC’s details page, with State: Available and IPv4 CIDR: 10.0.0.0/16.
Create the zone a subnets
In the AWS console: VPCSubnetsCreate subnet
For VPC ID, choose
quickcart-vpc. Fill in the first subnet, choose Add new subnet for each of the others, then choose Create subnet:Subnet name Availability Zone IPv4 subnet CIDR block quickcart-public-aus-east-1a 10.0.1.0/24quickcart-app-aus-east-1a 10.0.11.0/24quickcart-data-aus-east-1a 10.0.21.0/24You should seeThree subnets in the list. The Available IPv4 addresses column says 251 for each: 256 minus the five AWS keeps.
Create the zone b subnets
Same page, same VPC:
Subnet name Availability Zone IPv4 subnet CIDR block quickcart-public-bus-east-1b 10.0.2.0/24quickcart-app-bus-east-1b 10.0.12.0/24quickcart-data-bus-east-1b 10.0.22.0/24You should seeSix subnets, three in each zone, each with 251 available addresses.
Try a block that isn't on its boundary
Create one more subnet in
quickcart-vpc:Field Enter Subnet name quickcart-containers-aAvailability Zone us-east-1a IPv4 subnet CIDR block 10.0.33.0/20Choose Create subnet.
You should seequickcart-containers-ain the list with 4091 available addresses: 4,096 minus five.Try a range that overlaps
Create one more subnet:
Field Enter Subnet name quickcart-extra-aAvailability Zone us-east-1a IPv4 subnet CIDR block 10.0.40.0/24Choose Create subnet.
Clean-up step: Clean up
In the AWS console: VPCYour VPCsquickcart-vpcActionsDelete VPC
AWS lists the subnets that go with it. Type
deletein the box and choose Delete.You should seeThe VPC and all seven subnets are gone. Nothing was charged; keep your paper plan for the routing lesson.
Part 5: Check yourself
How many addresses are in 10.0.8.0/22?
A subnet is 10.0.11.0/24. How many addresses can you actually give to servers?
Why does AWS reject 10.0.1.0/20?
QuickCart is adding a VPC in a second region. Which range should it use, if the first VPC is 10.0.0.0/16?
You made the app subnets /24 and the service now needs far more addresses. What can you do?
Part 6: Cheat sheet
| Term | In one line |
|---|---|
| IPv4 address | 32 bits, written as four numbers from 0 to 255 |
/n | The first n bits are fixed. 32 − n bits are free |
| Addresses in a range | 2 to the power of the free bits |
/16 · /20 · /24 · /28 | 65,536 · 4,096 · 256 · 16 |
| Boundary rule | A block starts on a multiple of its own size |
| Reserved in every subnet | First four and the last: 5 addresses. A /24 has 251 usable |
| Subnet size limits | From /16 to /28 |
| Private ranges | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
| Growth | /16 per VPC, leave most of it unused. You can’t resize a subnet |
| Several VPCs | Never overlap: 10.0.0.0/16, 10.1.0.0/16, 10.2.0.0/16 |