
Can an Azure NSG be shared across multiple subnets? I tried swapping just one to a different NSG to find out
This page has been translated by machine translation. View original
Hello! I'm Yuji Nishimura from the Operations Department!
When you want to apply the same security rules to multiple subnets, do you need to create an Azure network security group (NSG) for each subnet?
One NSG can be shared by multiple subnets. On the other hand, a subnet can have at most one NSG associated with it. If you specify a different NSG for a subnet that has a shared NSG attached, the two NSGs are not applied on top of each other; instead, the association is replaced by the new NSG.
This time, I shared an NSG between two subnets that have no virtual machines (VMs) or similar resources placed in them, and then switched only one of the subnets to a different NSG. I checked the association state using both the result retrieved via the API and the portal display. What I checked was which NSG is associated with each subnet.
Multiple from the NSG's perspective, one from the subnet's perspective
According to the official virtual network (VNet) design guide, each subnet can have zero or one NSG associated with it, and you may use the same NSG for each subnet or a different NSG for each.
| Direction | Number that can be associated |
|---|---|
| NSG → subnet | Multiple subnets |
| Subnet → NSG | At most one NSG (zero is also fine) |
In AWS terms, this is close to how network ACL associations work. One network ACL can be associated with multiple subnets, and only one can be associated with a single subnet at a time. The only similarity is how associations are counted: network ACLs are stateless and every subnet always has exactly one attached. NSGs are stateful, and you can also leave a subnet without one.
Note that this "up to one" refers to the number of NSGs associated with a subnet and does not include the NSG attached to a network interface (NIC). According to the official explanation of how NSGs evaluate traffic, when NSGs are set on both the subnet and the NIC, traffic must be allowed by both NSGs in order to pass.
This time, I share nsg-shared between two subnets, app and batch, and then switch only app to nsg-dedicated. The following is a diagram I made to summarize that change. The lines represent resource associations and do not indicate communication paths.

Associating the same NSG with two subnets
I verified this on November 19, 2026, with macOS 26.7.2 and Azure CLI 2.91.0. I used a service principal with Contributor permissions on the verification subscription and created the VNet and NSGs in the Japan East region. I did not create any VMs or NICs.
The following are the CLI operations I ran. It assumes you are already logged in to the Azure CLI and have selected the target subscription. The shell variable rg holds the name of the verification resource group. I also create nsg-dedicated here, which I will switch app to later.
rg=blog-verify-azure-nsg-subnet-association
az group create -n "$rg" -l japaneast
az network nsg create -g "$rg" -n nsg-shared -l japaneast
az network nsg create -g "$rg" -n nsg-dedicated -l japaneast
az network vnet create -g "$rg" -n vnet-test -l japaneast \
--address-prefixes 10.42.0.0/16 \
--subnet-name app --subnet-prefixes 10.42.1.0/24
az network vnet subnet create -g "$rg" --vnet-name vnet-test \
-n batch --address-prefixes 10.42.2.0/24
I specified nsg-shared for both app and batch. For the --network-security-group option of subnet update, you can pass the name of an existing NSG.
for subnet in app batch; do
az network vnet subnet update -g "$rg" --vnet-name vnet-test \
-n "$subnet" --network-security-group nsg-shared
done
I retrieved the association of both subnets from the REST API (api-version 2025-01-01) using az rest. {subscriptionId} in the URL is automatically replaced by az rest with the ID of the subscription selected via az account set, so you can run it as is.
az rest --method get --url "/subscriptions/{subscriptionId}/resourceGroups/$rg/providers/Microsoft.Network/virtualNetworks/vnet-test/subnets?api-version=2025-01-01" \
--query 'value[].{name:name,state:properties.provisioningState,nsg:properties.networkSecurityGroup.id}' -o json
For both subnets, the end of properties.networkSecurityGroup.id was /networkSecurityGroups/nsg-shared, and provisioningState was Succeeded.
When I opened "Subnets" of vnet-test in the Azure portal, nsg-shared was also displayed in both rows. The red frame was added by me.

Switching only the app subnet to a different NSG
Next, I specified nsg-dedicated in the same region for app only. I did not perform any operation to remove the association with nsg-shared beforehand.
az network vnet subnet update -g "$rg" --vnet-name vnet-test \
-n app --network-security-group nsg-dedicated
The results retrieved again with the same REST API are as follows. The NSG names in the table are extracted from the end of the resource IDs.
| Subnet | Before | After | State after |
|---|---|---|---|
| app | nsg-shared | nsg-dedicated | Succeeded |
| batch | nsg-shared | nsg-shared | Succeeded |
Only the association of app changed to nsg-dedicated, and batch remained on nsg-shared. The result I checked in the portal was the same. The NSG name in the app row is abbreviated as nsg-dedica... because of the column width. The red frame was added by me.

Decide whether to share or separate NSGs based on whether you want to change the rules together
A shared NSG is a single entity, so changing its rules affects all the subnets associated with it. If the subnets have the same traffic requirements and the same timing for rule changes, you can consider sharing an NSG. On the other hand, if you want to change rules for only some of the subnets, or want to separate the people in charge or the approvers of changes, separating the NSGs limits the impact of rule changes to only the associated subnets.
Summary
I was able to share one NSG between two subnets. Because a subnet can have at most one NSG associated, specifying a different NSG for only app replaced only the association of app, and batch stayed on the shared NSG.
The rule of thumb is: share an NSG if you want to manage rules in one place, and separate NSGs if you want to change rules per subnet. In a real environment, also verify that the required traffic actually passes.