What is a Subnet?
A subnet is a range of IP addresses in your virtual network. Subnets enable you to segment your virtual network into smaller, manageable sections, apply network security policies, and allocate resources efficiently.
Key Concepts
- Address space: The CIDR block assigned to a virtual network (e.g.,
10.0.0.0/16
). - Subnet CIDR: A subset of the virtual network’s address space (e.g.,
10.0.1.0/24
). - Network Security Groups (NSGs): Bindable to subnets for traffic filtering.
- Service Endpoints: Extend Azure services into a subnet.
Creating a Subnet (Azure CLI)
az network vnet subnet create \
--resource-group MyResourceGroup \
--vnet-name MyVNet \
--name MySubnet \
--address-prefix 10.0.1.0/24 \
--network-security-group MyNSG \
--service-endpoints Microsoft.Storage
Creating a Subnet (PowerShell)
$subnet = New-AzVirtualNetworkSubnetConfig `
-Name "MySubnet" `
-AddressPrefix "10.0.1.0/24" `
-NetworkSecurityGroup $nsg `
-ServiceEndpoint @("Microsoft.Storage")
New-AzVirtualNetwork -Name "MyVNet" -ResourceGroupName "MyResourceGroup" `
-Location "EastUS" -AddressPrefix "10.0.0.0/16" -Subnet $subnet
ARM Template Example
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2022-07-01",
"name": "myVNet",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] },
"subnets": [
{
"name": "mySubnet",
"properties": {
"addressPrefix": "10.0.1.0/24",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', 'myNSG')]"
},
"serviceEndpoints": [
{ "service": "Microsoft.Storage" }
]
}
}
]
}
}
]
}
Subnet Limits
Region | Maximum Subnets per VNet |
---|---|
All regions | 3,000 |
Basic SKUs | 1,000 |
Best Practices
- Plan address space to avoid overlap with on-premises networks.
- Reserve address ranges for future use.
- Assign NSGs per subnet for logical security zones.
- Use service endpoints to secure Azure service access.
- Keep subnets small enough for manageable IP allocation.