IP addressing and subnetting
Read any CIDR range, count usable Azure addresses, find which subnet an IP belongs to, and plan a VNet without overlaps.
In this lesson you'll learn
- What an IP address and a /prefix actually mean
- How many addresses a subnet gives you in Azure, and why Azure keeps 5
- A repeatable method to find the network, range and broadcast of any address
- How to plan subnets for a real VNet and spot overlaps before peering
1. What is an IP address?
New to networking? Start here
An IP address is like a postal address for a device. The address 10.0.1.25 is four numbers called octets, each between 0 and 255, separated by dots.
Computers store each octet as 8 bits (ones and zeros), so a full IPv4 address is 32 bits. You rarely need to convert by hand, but knowing the place values makes subnetting click:
So 10 in binary is 00001010 (8 + 2), and 255 is 11111111 (every bit on).
Every IP address has two parts. The network part works like the street name, and every device on the same subnet shares it. The host part works like the house number, and it is unique to each device.
The number after the slash, called the prefix or CIDR notation, tells you where the split happens. /24 means the first 24 bits are the network part, leaving 8 bits for hosts.
2. Bigger prefix, smaller subnet
This trips up almost everyone at first. Each extra bit of prefix halves the size of the subnet, because one more bit is taken from the host part.
| Prefix | Subnet mask | Total addresses | Usable in Azure | Typical use |
|---|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,531 | A whole VNet address space |
| /20 | 255.255.240.0 | 4,096 | 4,091 | Large AKS subnet (Azure CNI) |
| /22 | 255.255.252.0 | 1,024 | 1,019 | Big scale set |
| /24 | 255.255.255.0 | 256 | 251 | General workload subnet |
| /25 | 255.255.255.128 | 128 | 123 | Web or app tier |
| /26 | 255.255.255.192 | 64 | 59 | AzureBastionSubnet, AzureFirewallSubnet |
| /27 | 255.255.255.224 | 32 | 27 | GatewaySubnet (recommended minimum) |
| /28 | 255.255.255.240 | 16 | 11 | Small database tier |
| /29 | 255.255.255.248 | 8 | 3 | Smallest subnet Azure allows |
Exam focus
Memorise this table from /24 to /29. Many questions are just "how many VMs fit in this subnet?" in disguise.
3. Why Azure keeps 5 addresses
In every Azure subnet, the first four addresses and the last one are reserved. You can never assign them to a VM.
Example
SS Kaiser asks for a subnet that can hold 30 web servers. A /27 has 32 addresses, so it looks perfect. But in Azure only 27 are usable, so 30 servers will not fit. The right answer is a /26, which gives 59 usable and leaves room to scale out during sales.
4. Find the subnet of any address
Exam questions often give you an address like 10.1.3.70/26 and ask which subnet it is in, or whether two addresses can talk directly. Use the block size method. It works without any binary.
- Find the interesting octet. /8 to /15 means octet 2, /16 to /23 means octet 3, and /24 to /32 means octet 4. For /26 it is the 4th octet.
- Work out the block size. Block size = 2(octet boundary minus prefix). The octet boundaries are 16, 24 and 32. For /26: 2(32 minus 26) = 64. So subnets start at 0, 64, 128 and 192.
- Find the block your number falls in. 70 sits between 64 and 127, so the network address is 10.1.3.64.
- Read off the range. Broadcast is the next block minus one (10.1.3.127). In Azure, usable is .68 to .126 (.64 to .67 are reserved).
Example: 172.16.45.200/20
- /20 is between /16 and /23, so the interesting octet is the 3rd one (45).
- Block size = 2(24 minus 20) = 16. Blocks are 0, 16, 32, 48 and so on.
- 45 falls in the block that starts at 32 (32 to 47).
- Network = 172.16.32.0/20. Broadcast = 172.16.47.255. Total 4,096 addresses, 4,091 usable in Azure.
5. How small can it be? Sizing for a number of hosts
Reverse the formula. Find the smallest subnet where 2host bits minus 5 is at least the number of addresses you need.
Example: an app tier with 100 VMs
- Try /25: 128 minus 5 = 123. That covers 100 VMs.
- Try /26: 64 minus 5 = 59. That is too small.
- Answer: /25, with 23 spare addresses for scaling or internal load balancer IPs.
Exam focus
Count everything that takes an IP: VMs, scale set instances, internal load balancer front ends, private endpoints and, with Azure CNI, every AKS pod. A question about 50 AKS pods per node across 3 nodes needs room for 150 pod IPs plus the nodes.
6. Plan a VNet: SS Kaiser
SS Kaiser is moving its online store to Azure. Its network team gives you these requirements:
- VNet address space 10.20.0.0/16, which leaves room to grow.
- Web tier: up to 80 VMs in a scale set.
- App tier: up to 100 VMs.
- Database tier: 10 VMs.
- A VPN gateway to the head office, and Azure Bastion for admin access.
Why this order? Placing the largest blocks first keeps every subnet on a clean boundary, so nothing overlaps and the rest of the /16 stays free in one piece.
Special subnet names and sizes
GatewaySubnet must use this exact name, and /27 or larger is recommended. AzureBastionSubnet must be /26 or larger. AzureFirewallSubnet must be /26. These names are case sensitive.
7. Overlaps: the peering killer
Two VNets can only be peered (or connected over VPN) if their address spaces do not overlap. To check, write each range as first address to last address and see whether they intersect.
Example
SS Kaiser acquires a smaller company whose Azure VNet also uses 10.20.0.0/16. Peering is impossible until one side is readdressed. That is why large organisations keep a central IP address plan before anyone creates a VNet.
8. Try it: subnet calculator
Type any address with a prefix. The bits light up so you can see the network and host parts.
Try it in the app. This lesson has an interactive calculator here. Open the lesson in the exam app
9. Practise: unlimited subnetting drills
Each question is generated fresh, with a full worked answer. Do ten in a row without a mistake and you are exam ready on this topic.
Try it in the app. This lesson has a practice drill here. Open the lesson in the exam app
Exam traps to remember
- Azure reserves 5 addresses per subnet, not 2 as in traditional networking.
- The smallest subnet is /29 (3 usable). /30, /31 and /32 are not allowed.
- You can add address ranges to a VNet later, even when it is peered (then sync the peering). You cannot shrink a subnet below the addresses already in use.
- Overlapping ranges block peering. Check this before anything else in a peering question.
Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-104 Azure Administrator app.
Practise in the app