NSGs, Application Security Groups and Effective Rules
30-second answer
A network security group (NSG) holds stateful allow and deny rules (source, destination, port, protocol), checked by priority from 100 to 4096, lowest number first; the first match wins. Every NSG has default rules at 65000 and above (allow VNet, allow Azure Load Balancer, deny all inbound). You attach an NSG to a subnet, a NIC, or both. For inbound traffic the subnet NSG is evaluated first, then the NIC NSG; outbound runs the other way, and both must allow. An application security group (ASG) groups NICs so rules can target "the web servers" instead of IP addresses. Effective security rules and IP flow verify show what really applies.
Simulate it » No Azure account neededExam objective: 4.2.1 Create and configure network security groups (NSGs) and application security groups. 4.2.2 Evaluate effective security rules in NSGs. (Skills measured as of April 17, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Search for <strong>application security groups</strong>.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Search for application security groups.
- Type application security groups in the search bar and pick Application security groups under Services.
- An ASG is just a label for NICs. Create asg-web in the same region as the VNet.
- On nic-web01, open Application security groups and add asg-web. All NICs in an ASG must be in the same VNet.
- In nsg-snet-web, add an inbound rule whose Destination is the ASG, not an IP list. New web VMs are covered the moment they join asg-web.
- Lowest number wins. Anything not allowed falls to DenyAllInBound at 65500. Default rules can't be deleted, only overridden by a lower number.
- Effective security rules shows every NSG that applies. Inbound, the subnet NSG is checked first, then the NIC NSG, and both must allow. Here the NIC NSG blocks 443.
- Network Watcher → IP flow verify names the exact rule. Add an allow for 443 on nsg-web01 (or remove that NSG) and verify again.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
NSGs, ASGs and effective rules
An NSG has rules checked by priority (100 to 4096, lowest first). Inbound traffic meets the subnet NSG first, then the NIC NSG, and both must allow. An application security group lets a rule say "to the web servers" instead of listing IPs.
🤔 What happens if…
Read this tour as text
- VNets, subnets and a public IP. A virtual network is your private range in one region, split into subnets. Azure keeps 5 addresses in every subnet. A Standard public IP is static, zone-redundant where the region has zones, and closed to inbound traffic until an NSG opens it.
- Peering is not transitive. VNet peering joins two VNets over the Microsoft backbone. Each side has its own link, address spaces can't overlap, and the hub can share its VPN gateway (gateway transit). Peering never chains: spoke 1 and spoke 2 can't talk through the hub on their own.
- User-defined routes to the NVA. A route table on a subnet overrides system routes. Next hop Virtual appliance sends traffic to a firewall or NVA, which needs IP forwarding on its NIC. Longest prefix wins, and a user route beats a system route on the same prefix.
- NSGs, ASGs and effective rules. An NSG has rules checked by priority (100 to 4096, lowest first). Inbound traffic meets the subnet NSG first, then the NIC NSG, and both must allow. An application security group lets a rule say "to the web servers" instead of listing IPs.
- Azure Bastion. Azure Bastion lives in AzureBastionSubnet (/26 or larger) and opens RDP and SSH to VMs on their private IPs, from the portal over TLS 443 or with the native client on Standard and Premium. One Bastion in the hub serves peered spokes.
- Service endpoint vs private endpoint. A service endpoint sends a subnet's traffic to the service's public IP over the backbone, and the service firewall allows that subnet. A private endpoint gives the service a private IP in your VNet, and a privatelink private DNS zone makes the name resolve to it.
- Azure DNS: public and private zones. A public zone answers the internet once you delegate the domain to Azure's name servers. Alias records point at Azure resources such as a public IP. A private zone answers only VNets with a virtual network link, and can auto-register VM names.
- Standard load balancer and health probes. A load balancer spreads TCP/UDP flows from a frontend (public or internal) to a backend pool by load-balancing rules. A health probe pulls a VM out of rotation when it stops answering. Probes come from 168.63.129.16.
- Troubleshoot with Network Watcher. Network Watcher tools answer one question each. IP flow verify: which NSG rule allows or denies this flow? Next hop: where does this packet go? Connection troubleshoot: can A reach B, and if not, at which hop?
The web tier must take HTTPS from the internet and nothing else. Write the subnet rule against an application security group instead of IP addresses, then watch a second NSG on the NIC quietly block it. Use IP flow verify and effective rules to prove what's happening, and fix it.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Every new web server means editing five NSG rules with new IP addresses.
😊 THE SOLUTION
Group the NICs in an application security group and write rules against the group.
- IP lists in every rule✓ Rules that target an ASG
- Allowed on the subnet, still blocked✓ Check the NIC NSG too
- Guessing which rule wins✓ Effective rules and IP flow verify
Start with a question
Why does a visitor get past reception but still can't open the lab door?
Reception checks the visitor list for the whole building. The lab has its own card reader with its own list. Being on reception’s list doesn’t put you on the lab’s.
A subnet NSG is reception and a NIC NSG is the lab door. Traffic coming in has to pass both. And instead of writing every visitor’s name, you can write “anyone with a contractor badge”. That badge is an application security group.
Explain it like I’m 10
The technical explanation
Rules
Each rule has a name, priority (100 to 4096), source and destination (IP, CIDR, service tag or ASG), source and destination ports, protocol (TCP, UDP, ICMP or Any), direction and action (Allow or Deny). Azure checks rules from the lowest number up and stops at the first match.
Default rules you can’t delete:
| Direction | Name | Priority | Effect |
|---|---|---|---|
| Inbound | AllowVnetInBound | 65000 | Allow from the VirtualNetwork tag (your VNet, peered VNets, on-premises via gateway) |
| Inbound | AllowAzureLoadBalancerInBound | 65001 | Allow health probes from 168.63.129.16 |
| Inbound | DenyAllInBound | 65500 | Deny everything else |
| Outbound | AllowVnetOutBound | 65000 | Allow to VirtualNetwork |
| Outbound | AllowInternetOutBound | 65001 | Allow to Internet |
| Outbound | DenyAllOutBound | 65500 | Deny everything else |
NSGs are stateful: when inbound traffic is allowed, its replies go out without an outbound rule. An NSG must be in the same region as what it’s attached to, and one NSG can be attached to many subnets and NICs.
Subnet NSG plus NIC NSG
-
1 Subnet NSG
Checked first. Deny here and the packet is dropped.
-
2 NIC NSG
Checked second. It must also allow the traffic.
-
3 VM
Only traffic both NSGs allow arrives. Outbound runs NIC first, then subnet.
Most designs put NSGs on subnets and avoid NIC NSGs unless one VM really needs different rules. Two layers make troubleshooting harder.
Application security groups
Create an ASG (for example asg-web), add NICs to it, and use it as the source or destination in NSG rules: Internet → asg-web : 443 allow, asg-web → asg-db : 1433 allow. New web servers just join the ASG. Limits: all NICs in an ASG are in the same VNet, and if a rule uses ASGs for both source and destination, they must be in the same VNet.
Effective security rules
On a running VM’s NIC, Help → Effective security rules shows each NSG that applies (subnet and NIC) with its merged rules. Network Watcher → IP flow verify tests one flow and names the rule that allowed or denied it. NSG diagnostics does the same for a broader range of sources.
Portal and CLI
Portal: Network security groups → + Create, then Inbound security rules → + Add, then Subnets → Associate (or NIC → Network security group). Application security groups → + Create, then on the NIC Application security groups → Add.
az network asg create -g rg-net-sec -n asg-web
az network nic create -g rg-net-sec -n nic-web01 --vnet-name vnet-app --subnet snet-web --application-security-groups asg-web
az vm create -g rg-net-sec -n web01 --image Ubuntu2204 --nics nic-web01
az network nsg create -g rg-net-sec -n nsg-snet-web
az network nsg rule create -g rg-net-sec --nsg-name nsg-snet-web -n Allow-HTTPS-to-web \
--priority 200 --direction Inbound --access Allow --protocol Tcp \
--source-address-prefixes Internet --destination-asgs asg-web --destination-port-ranges 443
az network vnet subnet update -g rg-net-sec --vnet-name vnet-app -n snet-web --network-security-group nsg-snet-web
az network nic list-effective-nsg -g rg-net-sec -n nic-web01
az network watcher test-ip-flow -g rg-net-sec --vm web01 --direction Inbound --protocol TCP \
--local 10.20.1.4:443 --remote 203.0.113.10:50000
PowerShell: New-AzNetworkSecurityRuleConfig, New-AzNetworkSecurityGroup, New-AzApplicationSecurityGroup, Get-AzEffectiveNetworkSecurityGroup.
Architect level Augmented rules and service tags
A single rule can list several IP ranges, ports and service tags (augmented security rules), so you rarely need dozens of near-identical rules. Service tags such as Storage.EastUS, Sql, AzureMonitor or GatewayManager are kept up to date by Microsoft, which is why they beat hard-coded IP lists for outbound rules to Azure services.
Real-world business scenario
Litware Health (fictional)
- The problem
- The patient portal's NSGs had 60 rules listing individual IPs. Every scale-out meant a ticket, and a forgotten NIC NSG kept new web servers dark for a day.
- What they used
- Three ASGs (asg-web, asg-api, asg-db) and one NSG per subnet with role-based rules: Internet to asg-web on 443, asg-web to asg-api on 8443, asg-api to asg-db on 1433. NIC-level NSGs removed. IP flow verify added to the runbook.
- Why that choice
- Rules describe roles, so scale-out needs no rule changes, and one NSG layer makes effective rules easy to read.
- The result
- The rule count dropped from 60 to 9, and new servers serve traffic as soon as they join their ASG.
When to use it and when not to
✓ Use it when…
- Allowing only the ports each tier needs, on every subnet.
- Role-based rules with ASGs so scale-out doesn't need rule edits.
- Effective rules and IP flow verify whenever traffic is mysteriously blocked.
✕ Think twice when…
- NSGs on both subnet and NIC without a reason. One layer is easier to troubleshoot.
- Filtering by domain name or with threat intelligence. That needs Azure Firewall.
- Opening RDP or SSH to the internet. Use Azure Bastion.
↔ Alternatives to consider
- Azure Firewall for FQDN rules, threat intelligence and central logging.
- Azure Virtual Network Manager security admin rules to enforce rules across many VNets.
- Azure Bastion instead of management ports open to the internet.
Test yourself with exercises
5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Two rules match the same traffic, one allows and one denies. Which wins?
Model answer
The one with the lower priority number. Azure processes rules from the lowest number up and stops at the first match, so priority 100 beats priority 200 regardless of which one allows.
Intermediate You allowed port 443 in the subnet NSG, but traffic is still blocked. Why?
Model answer
There's probably an NSG on the NIC too. Inbound traffic has to pass the subnet NSG and then the NIC NSG, and an NSG with no allow rule for 443 ends at DenyAllInBound. I'd open the NIC's effective security rules or run IP flow verify to see the exact rule.
Experienced developer Why use application security groups instead of IP addresses in rules?
Model answer
Rules then describe roles. "Internet to asg-web on 443, asg-web to asg-db on 1433" stays the same when servers are added, removed or re-addressed; you just put the new NIC in the ASG. The limits are that all NICs in an ASG must be in the same VNet, and ASGs used together in a rule must be in the same VNet too.
Scenario Security asks you to block all RDP from the internet but allow it from the office range 203.0.113.0/24. How do you write it?
Model answer
An allow rule for TCP 3389 from 203.0.113.0/24 at priority 100, and a deny rule for 3389 from Internet at priority 200. The office range matches first. Better still, remove the need entirely with Azure Bastion and only allow 3389 from the Bastion subnet.
Quick revision
Key points
- Rules have priority 100 to 4096, lowest first, first match wins. Defaults sit at 65000+.
- Inbound - subnet NSG then NIC NSG. Outbound - NIC NSG then subnet NSG. Both must allow.
- NSGs are stateful. Allowed inbound traffic gets its replies back automatically.
- ASGs group NICs (same VNet) so rules target roles, not IPs.
- Effective security rules and IP flow verify show the real result.
Important terminology
- Network security group (NSG)
- A set of stateful allow and deny rules for inbound and outbound traffic, attached to subnets and/or network interfaces.
- Priority
- A number from 100 to 4096. Lower numbers are processed first, and processing stops at the first match.
- Default security rules
- AllowVnetInBound (65000), AllowAzureLoadBalancerInBound (65001), DenyAllInBound (65500), and the outbound equivalents including AllowInternetOutBound. They can't be deleted, only overridden.
- Service tag
- A Microsoft-maintained name for a group of IP ranges, such as Internet, VirtualNetwork, AzureLoadBalancer or Storage.
- Application security group (ASG)
- A label you attach to NICs so NSG rules can use it as a source or destination instead of IP addresses.
- Effective security rules
- The combined rules from every NSG that applies to a NIC, shown on the NIC in the portal or with az network nic list-effective-nsg.
Common mistakes
- Forgetting a NIC-level NSG when you've only checked the subnet.
- Assuming a higher number has higher priority.
- Blocking the AzureLoadBalancer tag and breaking health probes.
Exam tips
- "Which rule applies?" = find the lowest priority number that matches.
- "Allowed on the subnet but still blocked" = check the NIC NSG.
- "Rules must not change when servers are added" = application security groups.
Five quick revision questions
-
1.What is the valid priority range for custom rules?Show
100 to 4096.
-
2.Which NSG is evaluated first for inbound traffic?Show
The subnet NSG.
-
3.What is the priority of DenyAllInBound?Show
65500.
-
4.Can an ASG contain NICs from different VNets?Show
No.
-
5.Which CLI command shows effective rules on a NIC?Show
az network nic list-effective-nsg.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Connect to VMs Securely with Azure Bastion
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.