IP addressing and subnetting

AZ-104 Azure AdministratorNetworkingAbout 35 minutesBy Cloud Hands On

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

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:

1286432168421

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.

10.0.1.0/24 split into a 24-bit network part and an 8-bit host part 10010 ... 00001010000000000000000100000000 Network part: 24 bits, fixed for the subnet Host part: 8 bits 2⁸ = 256 addresses
A /24 fixes the first three octets. The last octet is free for hosts.
The one formula you need: addresses in a subnet = 2(32 minus prefix). A /24 gives 28 = 256. A /27 gives 25 = 32.

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.

PrefixSubnet maskTotal addressesUsable in AzureTypical use
/16255.255.0.065,53665,531A whole VNet address space
/20255.255.240.04,0964,091Large AKS subnet (Azure CNI)
/22255.255.252.01,0241,019Big scale set
/24255.255.255.0256251General workload subnet
/25255.255.255.128128123Web or app tier
/26255.255.255.1926459AzureBastionSubnet, AzureFirewallSubnet
/27255.255.255.2243227GatewaySubnet (recommended minimum)
/28255.255.255.2401611Small database tier
/29255.255.255.24883Smallest 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.

The 8 addresses of 10.0.0.0/29, with 5 reserved and 3 usable .0.1.2.3.4.5.6.7 NetworkDefaultgatewayAzure DNSUsable by your VMsBroadcast 8 total, minus 5 reserved = 3 usable. The first VM gets 10.0.0.4.
The same pattern applies to every subnet size. Only the count in the middle changes.
Azure usable addresses = 2(32 minus prefix) minus 5

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.

  1. 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.
  2. 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.
  3. Find the block your number falls in. 70 sits between 64 and 127, so the network address is 10.1.3.64.
  4. 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).
The 4th octet split into four /26 blocks of 64, with 70 falling in the second block .0 to .63.64 to .127.128 to .191.192 to .255 10.1.3.70 lands here Network 10.1.3.64/26, broadcast 10.1.3.127
For /26 the 4th octet is cut into blocks of 64.
Example: 172.16.45.200/20
  1. /20 is between /16 and /23, so the interesting octet is the 3rd one (45).
  2. Block size = 2(24 minus 20) = 16. Blocks are 0, 16, 32, 48 and so on.
  3. 45 falls in the block that starts at 32 (32 to 47).
  4. 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
  1. Try /25: 128 minus 5 = 123. That covers 100 VMs.
  2. Try /26: 64 minus 5 = 59. That is too small.
  3. 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.
SS Kaiser subnet plan with five subnets packed from 10.20.0.0 webappdbGatewaySubnetAzureBastionSubnetFree for growth 10.20.0.0/25, 123 usable10.20.0.128/25, 123 usable10.20.1.0/27, 27 usable10.20.1.32/27, required name10.20.1.64/26, /26 minimum10.20.1.128 onwards
Largest subnets first, packed in order. Bar length shows relative size.

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.

VNet4 10.10.128.0/17 sits inside VNet2 10.10.0.0/16, so they overlap. VNet3 10.11.0.0/16 does not. 10.10.0.010.10.128.010.11.0.010.11.255.255 VNet2 10.10.0.0/16 VNet4 10.10.128.0/17 VNet3 10.11.0.0/16
VNet4 is the second half of VNet2, so they overlap and cannot be peered. VNet3 starts exactly where VNet2 ends.

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

Keep going