Azure Virtual Networks and Subnets
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
An Azure virtual network (VNet) is your own private network inside Azure. Your VMs, databases and private endpoints sit in its subnets and talk to each other on private IP addresses, much like servers on an office network.
Whatever address range you choose on day one is very hard to change later, because peering, VPNs and firewalls all depend on it, so this lesson starts with a small IP plan before building anything.
You’ll create vnet-saat, which you’ll keep using for the rest of the course, with private subnets that have no hidden internet access. That’s how Azure has built new networks since 31 March 2026.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 40 minutes | The CLI, signed in | Nothing (VNets and subnets cost nothing) | Plan an address range, build a VNet with private subnets, and read subnet errors |
What it is, in one line
A virtual network is a private, isolated network in one Azure region, divided into subnets, where your resources get private IP addresses.
In Simple Words
Plots and houses in a new colony
Picture a builder who gets a big plot of land for a new colony and numbers the houses: 10.30 is the colony, and each lane gets its own block of numbers. Lane 1 is shops, lane 2 is homes, and lane 3 is for the water tank and the generator.
The colony is your VNet and each lane is a subnet. Give two lanes the same house numbers and the postman gets confused, and if you make a lane too short, there’s no room to add houses later.
And the gate at the colony entrance stays shut unless you build one deliberately, which is what a “private subnet” means.
Engineer's View
Address spaces, subnets and reserved IPs
- Address space: one or more private CIDR blocks for the whole VNet, normally taken from RFC 1918 (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16). It can’t overlap your on-premises networks or any VNet you might connect to later. - Subnets: slices of the address space. Each one has to fit inside it without overlapping another subnet. Resources in different subnets of the same VNet can reach each other by default, and NSGs (Lesson 12) are how you control that.
- Five reserved addresses per subnet: the network address,
.1for the default gateway,.2and.3for Azure DNS, and the last address. So a/24gives you 251 usable IPs instead of 254, and the smallest subnet you can make is a/29(3 usable). - Special subnets have to use exact names:
AzureBastionSubnet(/26 or larger),AzureFirewallSubnet(/26) andGatewaySubnet(/27 or larger is recommended). - Private subnets: since 31 March 2026, new VNets made with current API versions get private subnets by default (
defaultOutboundAccess: false). VMs in them can reach Azure Storage in the same region but not the internet, until you add a NAT Gateway, a public IP, a load balancer outbound rule or a firewall (Lesson 13). VNets that already existed keep the old behaviour.
A VNet belongs to one region and one subscription. To connect VNets you need peering or a gateway, and neither will accept overlapping ranges. Changing a range that’s in use, peered or connected to a VPN is painful, which is why a written IP plan is worth more than any template.
How it works, step by step
This is the IP plan the course uses. It leaves room to grow, and the special subnets sit at the top of the range where they’re easy to spot:
| Subnet | Range | Usable IPs | Used for |
|---|---|---|---|
snet-web | 10.30.1.0/24 | 251 | Web servers, load balancer back ends |
snet-app | 10.30.2.0/24 | 251 | App servers |
snet-data | 10.30.3.0/24 | 251 | Databases, private endpoints |
snet-mgmt | 10.30.10.0/24 | 251 | Admin and automation VMs |
AzureBastionSubnet | 10.30.250.0/26 | 59 | Bastion Basic or Standard (Lesson 27) |
AzureFirewallSubnet | 10.30.254.0/26 | 59 | Azure Firewall (Lesson 48) |
GatewaySubnet | 10.30.255.0/27 | 27 | VPN Gateway (Lesson 49) |
The ranges 10.30.4.0 to 10.30.9.255 and 10.30.11.0 upwards are kept free for future subnets. The “office” network in the later hybrid labs is 10.80.0.0/16, and the hub-and-spoke lessons use 10.40.0.0/16 to 10.42.0.0/16, so nothing overlaps anywhere.
When a VM needs an IP, Azure’s own DHCP gives it the next free address in the subnet, starting from .4. Its default gateway is .1 and its DNS server is Azure’s resolver at 168.63.129.16. On Azure you don’t set a static IP inside the OS, you set it on the network interface.
In the lab you’ll build the four workload subnets now. Each special subnet gets created in its own lesson, so none of them sit empty and confuse people.
Hands-on lab: plan and build vnet-saat
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
You’ll write a small calculator to check the plan, build vnet-saat in a resource group that stays around, look at which IPs are taken, and save the IDs for later lessons.
1Check the plan with a subnet calculator
Paste this whole block:
function Get-SubnetInfo {
param([Parameter(Mandatory)][string]$Cidr)
$ip, $bits = $Cidr -split '/'
$b = ([System.Net.IPAddress]$ip).GetAddressBytes()
[int64]$n = ($b[0] * 16777216) + ($b[1] * 65536) + ($b[2] * 256) + $b[3]
[int64]$size = [math]::Pow(2, 32 - [int]$bits)
$start = [math]::Floor($n / $size) * $size
$toIp = { param($v) '{0}.{1}.{2}.{3}' -f [math]::Floor($v / 16777216), ([math]::Floor($v / 65536) % 256), ([math]::Floor($v / 256) % 256), ($v % 256) }
[pscustomobject]@{
Cidr = $Cidr
Network = & $toIp $start
FirstUsable = & $toIp ($start + 4)
LastUsable = & $toIp ($start + $size - 2)
Total = $size
Usable = $size - 5
}
}
'10.30.0.0/16','10.30.1.0/24','10.30.250.0/26','10.30.255.0/27' | ForEach-Object { Get-SubnetInfo $_ } | Format-TableYou should see this:
Cidr Network FirstUsable LastUsable Total Usable
---- ------- ----------- ---------- ----- ------
10.30.0.0/16 10.30.0.0 10.30.0.4 10.30.255.254 65536 65531
10.30.1.0/24 10.30.1.0 10.30.1.4 10.30.1.254 256 251
10.30.250.0/26 10.30.250.0 10.30.250.4 10.30.250.62 64 59
10.30.255.0/27 10.30.255.0 10.30.255.4 10.30.255.30 32 27This output is exact, since it’s plain arithmetic. The first usable address is always .4 and the last one sits just below the broadcast address, because Azure keeps five for itself.
2Create the core resource group and the VNet
Run this:
az group create --name rg-saat-core --tags course=saatvedha-azure lesson=11 keep=true -o none
az network vnet create --resource-group rg-saat-core --name vnet-saat --address-prefixes 10.30.0.0/16 --tags course=saatvedha-azure lesson=11 keep=true -o none
$subnets = @{ 'snet-web' = '10.30.1.0/24'; 'snet-app' = '10.30.2.0/24'; 'snet-data' = '10.30.3.0/24'; 'snet-mgmt' = '10.30.10.0/24' }
foreach ($name in $subnets.Keys) {
az network vnet subnet create --resource-group rg-saat-core --vnet-name vnet-saat --name $name --address-prefixes $subnets[$name] --default-outbound-access false -o none
}
az network vnet subnet list --resource-group rg-saat-core --vnet-name vnet-saat --query "sort_by(@, &addressPrefix)[].{name:name, prefix:addressPrefix, defaultOutbound:defaultOutboundAccess}" -o tableYou should see something like this:
Name Prefix DefaultOutbound
--------- ------------- -----------------
snet-web 10.30.1.0/24 False
snet-mgmt 10.30.10.0/24 False
snet-app 10.30.2.0/24 False
snet-data 10.30.3.0/24 Falsesort_by sorts as text, so 10.30.10.0 comes before 10.30.2.0, the way words are sorted. --default-outbound-access false makes each subnet private explicitly, so you get the same result whatever API version your tools use. The tag keep=true marks resources that stay between lessons.
3Check which addresses are free
Run this:
az network vnet check-ip-address --resource-group rg-saat-core --name vnet-saat --ip-address 10.30.1.4
az network vnet check-ip-address --resource-group rg-saat-core --name vnet-saat --ip-address 10.30.1.2 --query availableYou should see something like this:
{
"available": true
}
false.4 is the first address a VM can be given, and .2 belongs to Azure DNS, so it’s never free. This command comes in handy before you give a VM a static private IP.
4Save the IDs for later lessons
Run this:
$v = [ordered]@{ ResourceGroup = 'rg-saat-core'; VnetName = 'vnet-saat' }
$v.VnetId = az network vnet show -g rg-saat-core -n vnet-saat --query id -o tsv
foreach ($name in 'snet-web','snet-app','snet-data','snet-mgmt') {
$v[$name] = az network vnet subnet show -g rg-saat-core --vnet-name vnet-saat -n $name --query id -o tsv
}
$v | ConvertTo-Json | Set-Content C:\azure-lab\vnet-saat.json
(Get-Content C:\azure-lab\vnet-saat.json | ConvertFrom-Json).'snet-web'You should see something like this:
/subscriptions/6f1c2d3e-.../resourceGroups/rg-saat-core/providers/Microsoft.Network/virtualNetworks/vnet-saat/subnets/snet-webFrom here on, the labs load this file with $v = Get-Content C:\azure-lab\vnet-saat.json | ConvertFrom-Json so you don’t have to look the IDs up again.

✅ Checkpoint: vnet-saat has four private subnets, and C:\azure-lab\vnet-saat.json holds their IDs. Keep both for the rest of the course.
Break It, Then Fix It
Azure checks each subnet against the VNet and against the subnets next to it, and these two errors are the ones you’ll run into most.
1Break it: a subnet that overlaps another
Run this:
az network vnet subnet create --resource-group rg-saat-core --vnet-name vnet-saat --name snet-test --address-prefixes 10.30.1.128/25 --default-outbound-access falseYou’ll get an error like this:
(NetcfgSubnetRangesOverlap) Subnet 'snet-test' is not valid because its IP address range overlaps with that of an existing subnet in the virtual network.
Code: NetcfgSubnetRangesOverlap10.30.1.128/25 is the top half of snet-web. Run Get-SubnetInfo 10.30.1.128/25 and you’ll see it starts at 10.30.1.128, which is inside snet-web’s 10.30.1.0 to 10.30.1.255.
To fix it, take a free range from the plan:
az network vnet subnet create --resource-group rg-saat-core --vnet-name vnet-saat --name snet-test --address-prefixes 10.30.4.0/24 --default-outbound-access false --query addressPrefix -o tsvYou should see this:
10.30.4.0/242Break it: a subnet outside the VNet
Run this:
az network vnet subnet create --resource-group rg-saat-core --vnet-name vnet-saat --name snet-test2 --address-prefixes 10.31.1.0/24 --default-outbound-access falseYou’ll get an error like this:
(NetcfgSubnetRangeOutsideVnet) Subnet 'snet-test2' is not valid because its IP address range is outside the IP address range of virtual network 'vnet-saat'.
Code: NetcfgSubnetRangeOutsideVnetThe VNet is 10.30.0.0/16 and 10.31.1.0/24 falls outside it. You could add a second address space to the VNet, but on a real network that range would also need to be free in every peered network and on-premises.
Azure has nothing to fix, because the subnet was never created. Remove the test subnet from step 1:
az network vnet subnet delete --resource-group rg-saat-core --vnet-name vnet-saat --name snet-test
az network vnet subnet list --resource-group rg-saat-core --vnet-name vnet-saat --query "length(@)"You should see this:
4
✅ Checkpoint: Both errors reproduced, the test subnet removed, and vnet-saat has its four subnets again. Nothing to clean up: the VNet stays.
From now on C:\azure-lab\Find-LabResources.ps1 will always list rg-saat-core and vnet-saat, and that’s expected, because they carry keep=true and cost nothing.
This happened at work
The sale-day subnet that ran out of addresses
An online fashion store ran its web tier on a VM scale set in a /27 subnet, which gives 27 usable addresses. That seemed like plenty, since the scale set usually ran 8 VMs.
Then came the first morning of a big festival sale, and autoscale tried to go from 12 to 40 VMs. Once the 27 IPs were used up (less the load balancer’s own front end and two old test VMs nobody had cleaned up), new instances started failing with SubnetIsFull. For two hours the site crawled while the team made a new /23 subnet and a second scale set by hand.
What they changed: any subnet for something that scales is now sized for the peak, plus room for rolling upgrades, which need extra instances for a short while. The IP plan is written down next to the Bicep files, and an Azure Monitor alert goes off when a subnet uses more than 70 percent of its addresses.
Common mistakes and troubleshooting
| Mistake | What you see | What to do |
|---|---|---|
| Using 10.0.0.0/16 everywhere | Can’t peer or VPN later: ranges overlap | Keep an IP plan and give each VNet its own range. |
| Forgetting the five reserved IPs | Fewer addresses than expected; SubnetIsFull | A /24 gives 251, so plan for the peaks. |
| Host bits in the prefix, like 10.30.1.10/24 | InvalidCIDRNotation | Use the network address, 10.30.1.0/24, which Get-SubnetInfo shows you. |
| Wrong special subnet name | Bastion, Firewall or VPN Gateway can’t be created | Use AzureBastionSubnet, AzureFirewallSubnet and GatewaySubnet, spelled exactly like that. |
| Assuming new VMs have internet | apt or Windows Update times out | New subnets are private, so add a NAT Gateway or another outbound method (Lesson 13). |
| Setting a static IP inside the OS | The VM loses network after a reboot | Set static private IPs on the VM’s network interface in Azure. |
Interview questions
Click a question to open it. Each one is worded the way an interviewer would put it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. What is a virtual network in Azure?
Why they ask this: A basic concept check.
How you might answer: It’s a private, isolated network in one region where Azure resources get private IP addresses and can reach each other. You divide it into subnets and control the traffic with NSGs and route tables.
2. How many usable IPs are in a /24 subnet in Azure, and why?
Why they ask this: They want to see you know Azure’s reserved addresses.
How you might answer: 251, because Azure keeps five for itself: the network address, .1 for the gateway, .2 and .3 for DNS, and the last address.
3. What changed for new virtual networks in March 2026?
Why they ask this: They’re checking that your knowledge is current.
How you might answer: New VNets get private subnets by default, so VMs don’t get that hidden default outbound internet access any more and you have to add an explicit outbound method, like NAT Gateway, a public IP or a firewall. Networks that already existed weren’t touched.
2–5 years experience
4. How would you pick an address range for a new VNet?
Why they ask this: They want to hear a plan, not a range picked at random.
How you might answer: I’d look at the company’s IP plan for on-premises and all the other VNets first, then choose a free private range with room to grow, something like a /16 or /20 per environment. I’d size the subnets for peak use and give the special subnets for Bastion, Firewall and gateways their own blocks.
5. A VM in a new subnet can’t download updates. What’s the likely cause?
Why they ask this: They want current knowledge of default outbound access.
How you might answer: If the subnet is private, which new VNets are by default, the VM has no way out to the internet. I’d check the subnet’s defaultOutboundAccess setting and add a NAT Gateway or another explicit outbound method, and after that I’d look at the NSGs and any route tables sending traffic somewhere else.
6. Can you change a subnet’s address range after it’s in use?
Why they ask this: They want practical knowledge of the limits.
How you might answer: Only if the new range still covers every IP already in use in that subnet and doesn’t overlap anything, and you can’t shrink it below what’s in use. In practice it’s usually easier to make a new subnet and move the resources over.
Senior level
7. Design the IP plan for a company with three environments, a hub network and two offices.
Why they ask this: They want a structured, non-overlapping design with room to grow.
How you might answer: I’d set aside a big block for Azure, say 10.40.0.0/14, and give the hub a /22 and each environment its own /16 or smaller out of it. The offices keep their current ranges, and I’d write those down first so nothing clashes. All of it goes into a shared IP plan, ideally in an IPAM tool, and new VNets take their ranges from there.
8. Two companies merge and both used 10.0.0.0/16 in Azure. How do you connect them?
Why they ask this: They’re checking you know overlaps block peering and what the options are.
How you might answer: Peering and VPN routing won’t work when the ranges overlap. You can re-address one side, which is the clean fix but takes time, or put NAT in the middle, a firewall or a NAT-capable gateway for example, for the few services that have to talk. Longer term I’d plan the re-addressing and use a central IP plan so it doesn’t happen again.
9. How would you stop teams from creating VNets with overlapping ranges?
Why they ask this: They want governance, not just a document.
How you might answer: I’d use a central IP plan, or Azure Virtual Network Manager IPAM pools, to hand out ranges, and add an Azure Policy that denies any VNet outside the allowed ranges. VNets get built from shared Bicep modules that take their range from the plan, and a regular report picks up any overlaps.
Quick quiz
Q1. How many usable addresses does a /26 subnet have in Azure?
- 64
- 62
- 59
- 27
Show answer
C — 64 minus the five Azure keeps is 59.
Q2. Which address in a subnet is Azure’s default gateway?
- .0
- .1
- .4
- .255
Show answer
B — .1 is the gateway; .2 and .3 are DNS.
Q3. What does defaultOutboundAccess false mean for a subnet?
- No traffic at all
- No hidden internet access; you need an explicit outbound method
- No DNS
- No private IPs
Show answer
B — Private subnets need NAT Gateway, a public IP, a load balancer rule or a firewall for internet access.
Q4. Which error means a new subnet overlaps an existing one?
- NetcfgSubnetRangeOutsideVnet
- NetcfgSubnetRangesOverlap
- InvalidCIDRNotation
- SubnetIsFull
Show answer
B — Subnets in one VNet can’t overlap.
Q5. What must the Bastion subnet be called?
- BastionSubnet
- snet-bastion
- AzureBastionSubnet
- GatewaySubnet
Show answer
C — Special subnets need exact names.
Quick recap
You now have a planned, private network, and every later lab builds on it.
- A VNet is a private network in one region; subnets slice its address space.
- Azure keeps five IPs per subnet: a /24 gives 251.
- New subnets are private by default since March 2026; outbound internet needs an explicit method.
- Subnets can’t overlap each other or fall outside the VNet.
- vnet-saat (10.30.0.0/16) and C:\azure-lab\vnet-saat.json stay for the course.
Next lesson
Lesson 12: NSG vs ASG: network security groups and application security groups → You control traffic between the subnets with NSG rules, and group servers by role with ASGs.
Further reading: Azure virtual network
Want to go deeper into Azure virtual network? Read Microsoft’s What is Azure Virtual Network? and Default outbound access in Azure. You can also see the full plan for this course on the Azure Cloud Administration course page.
