FREE STUDY NOTES · AZ-104

How Azure NSG rules are evaluated (subnet vs NIC, priority, default rules)

The order Azure applies subnet and NIC network security groups for inbound and outbound traffic, how priority works, and a worked example.

From Ultra Transcenders AZ-104 by Tony Rough

Once an NSG is associated, Azure evaluates its rules in a strict order. Most NSG troubleshooting comes down to working out which rule matches first.

Priority and first match

Rules are processed in ascending priority order (lower number first); the first matching rule applies and processing stops. Custom priorities range from 100 to 4096, and the default rules sit at 65000-65500 (so 64999 isn’t a valid custom priority).

To allow traffic that is currently blocked, add an Allow rule with a lower priority number than the Deny rule. A Deny rule never makes traffic succeed. If an allow rule is already at 100, it can’t gain precedence, so the block must be somewhere else (another NSG or the rule’s criteria).

Worked examples:

Subnet and NIC NSGs together

Inbound traffic must be allowed by both the subnet NSG (evaluated first) and the NIC NSG.

NSGs are stateful: return traffic for an allowed flow is allowed automatically, so you don’t need a matching rule in the other direction.

For outbound traffic the order is reversed: the NIC NSG is evaluated first, then the subnet NSG. (See Figure 12.1.)

Inbound traffic is checked by the subnet NSG and then the NIC NSG before reaching the VM; outbound traffic is checked by the NIC NSG first and then the subnet NSG. Inside one NSG, rules are read in priority order and the first match wins: with a deny for TCP 50-60 at 100 and an allow for TCP 50-500 at 400, port 53 is blocked and port 443 allowed. The default rules sit at 65000-65500.
Figure 12.1: How NSG rules are evaluated

Default rules

Default rule Priority Effect
AllowVNetInBound 65000 Traffic within the VNet and peered VNets
AllowAzureLoadBalancerInBound 65001 Health probe traffic
DenyAllInBound 65500 Everything else, including internet
AllowVnetOutBound 65000 VM-initiated traffic to VNet/peered VNets
AllowInternetOutBound 65001 Outbound internet
DenyAllOutBound 65500 Everything else outbound

You can’t delete the default rules, but custom rules with a higher priority (a lower number) override them.

Reading rules correctly

Get the whole book

This note is one section of Ultra Transcenders AZ-104: Microsoft Azure Administrator, an independent study guide that explains every topic the exam covers by technology, with comparison tables, diagrams and the common traps, plus a glossary linked to Microsoft Learn.

Amazon.co.ukKindlePaperback
Amazon.comKindlePaperback

Opens Amazon in a new tab.

About the book · Free AZ-104 glossary · All AZ-104 study notes

More AZ-104 study notes