What Are Subnets?
A subnet is a range of IP addresses within a VNet. You deploy resources into subnets — every VM NIC, every PaaS service that integrates with a VNet, must go into a subnet. Subnets serve two purposes:
- Organisation — Group related resources (web tier, app tier, data tier) into separate subnets
- Security — Apply NSGs to control traffic between subnets
Subnet Sizing
Remember Azure reserves 5 IPs per subnet. Here's a quick guide for common subnet sizes:
| CIDR | Total IPs | Usable IPs | Suitable For |
|---|---|---|---|
| /24 | 256 | 251 | General-purpose subnet, most workloads |
| /25 | 128 | 123 | Medium workload subnet |
| /26 | 64 | 59 | Small subnet, Azure Bastion minimum |
| /27 | 32 | 27 | Very small subnet |
| /28 | 16 | 11 | Minimal subnet — VPN Gateway minimum |
| /29 | 8 | 3 | Extremely limited — avoid |
Private IP Addresses
Every resource in a subnet gets a private IP from the subnet's address range. Private IPs are used for communication within the VNet (and connected networks).
Dynamic vs Static Private IPs
| Dynamic | Static | |
|---|---|---|
| Assignment | Azure assigns next available IP | You specify the IP address |
| Changes on restart? | No — stays the same (but not guaranteed forever) | Never changes |
| Changes on delete/recreate? | May change | Must be reassigned |
| Best for | Most VMs and resources | DNS servers, domain controllers, load balancers |
# Create NIC with static private IP
az network nic create \
--resource-group myRG \
--name myNIC \
--vnet-name myVNet \
--subnet web-subnet \
--private-ip-address 10.0.1.10
Public IP Addresses
Resources that need to be reachable from the internet require a public IP. Public IPs are separate resources that are attached to NICs, load balancers, or gateways.
| Basic SKU | Standard SKU | |
|---|---|---|
| Assignment | Dynamic or static | Static only |
| Security | Open by default | Closed by default — NSG required |
| Zone support | No | Yes — zone-redundant or zonal |
| Load Balancer support | Basic LB only | Standard LB only |
| Recommended? | Legacy — avoid for new | Yes — always use Standard |
# Create a Standard SKU static public IP
az network public-ip create \
--resource-group myRG \
--name myPublicIP \
--sku Standard \
--allocation-method Static \
--zone 1 2 3 \
--location centralindia
Public IP Prefixes
A Public IP Prefix is a reserved contiguous block of Standard public IP addresses. Useful when you need multiple public IPs from the same range (for whitelisting in firewalls).
Service-Dedicated Subnets
Some Azure services require their own dedicated subnet with a specific name:
| Service | Required Subnet Name | Minimum Size |
|---|---|---|
| Azure Bastion | AzureBastionSubnet | /26 |
| VPN Gateway | GatewaySubnet | /27 (recommend /26) |
| Azure Firewall | AzureFirewallSubnet | /26 |
| Azure Firewall Management | AzureFirewallManagementSubnet | /26 |
| App Gateway v2 | Any name | /24 recommended |
| Azure Route Server | RouteServerSubnet | /27 |
Subnet Delegation
Subnet delegation allows you to designate a subnet for a specific Azure service — allowing that service to create resources in the subnet and manage certain configurations. Common delegated services:
- Azure App Service (for VNet Integration)
- Azure Kubernetes Service (for AKS node pools)
- Azure NetApp Files
- Azure SQL Managed Instance
Creating and Managing Subnets
# Add a subnet
az network vnet subnet create \
--name data-subnet \
--resource-group myRG \
--vnet-name myVNet \
--address-prefix 10.0.3.0/24
# List subnets
az network vnet subnet list \
--resource-group myRG \
--vnet-name myVNet \
--output table
# Show subnet details
az network vnet subnet show \
--resource-group myRG \
--vnet-name myVNet \
--name data-subnet
# Update subnet (e.g., add NSG)
az network vnet subnet update \
--resource-group myRG \
--vnet-name myVNet \
--name data-subnet \
--network-security-group myNSG
Subnet Design Patterns
A typical 3-tier application subnet layout:
| Subnet | CIDR | Resources | NSG |
|---|---|---|---|
| AzureBastionSubnet | 10.0.0.0/26 | Azure Bastion | Bastion NSG |
| GatewaySubnet | 10.0.0.64/27 | VPN Gateway | None (required) |
| web-subnet | 10.0.1.0/24 | Web VMs, App Gateway | Allow 80/443 inbound |
| app-subnet | 10.0.2.0/24 | Application VMs | Allow only from web-subnet |
| data-subnet | 10.0.3.0/24 | SQL, databases | Allow only from app-subnet |