Azure Networking – Subnets

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

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

RegionMaximum Subnets per VNet
All regions3,000
Basic SKUs1,000

Best Practices