What is a Network Security Group and how are its rules evaluated?

BeginnerConceptNetworking
Answer

An NSG is a stateful packet filter with priority-ordered rules (100–4096, lower first; first match wins). It attaches to a subnet, a NIC, or both. Each rule matches source, source port, destination, destination port, protocol, and allows or denies.

Default rules (priority 65000+) allow traffic within the VNet and from Azure Load Balancer inbound, deny all other inbound, and allow all outbound. Return traffic of an allowed flow is permitted automatically.

az network nsg rule create -g rg -n allow-https --nsg-name nsg-web --priority 100 \
  --direction Inbound --access Allow --protocol Tcp \
  --source-address-prefixes Internet --destination-port-ranges 443
Azure All Azure questions Roadmap: Azure core services

More on Networking