Network Security Groups and Application Security Groups
A Network Security Group (NSG) contains rules that allow or deny traffic. Each rule specifies a source, destination, port, protocol, and action. Rules are evaluated in priority order, lowest number first. The first matching rule wins: Azure stops evaluating lower-priority rules once a match is found. Every NSG has default rules at high priority numbers (65000, 65001, 65500) that allow VNet-internal traffic, allow Azure Load Balancer traffic, and deny all other inbound traffic. You cannot delete default rules but can override them by adding rules at lower priority numbers.
NSGs can be attached to subnets (applying to all resources in the subnet) and to individual NICs (applying only to that specific network interface). When an NSG is attached to both the subnet and the NIC, traffic must satisfy both NSGs: the subnet NSG is evaluated first for inbound traffic, then the NIC NSG. For outbound traffic, the NIC NSG is evaluated first, then the subnet NSG. NSGs are stateful: if you allow inbound traffic on port 80, the response traffic is automatically permitted without a separate outbound rule.
Application Security Groups (ASGs) let you group VMs logically and reference those groups in NSG rules. Instead of specifying individual IP addresses for your web servers, you assign those VMs to a WebServer ASG and write a rule that allows traffic to the WebServer ASG. When new web servers are added to the ASG, they automatically inherit the rules. ASGs simplify NSG management in environments where IP addresses change or where you want to express security policy in application terms rather than network terms.
Azure Firewall, User Defined Routes, and Azure Bastion
Azure Firewall is a fully managed, stateful network firewall deployed in its own dedicated subnet (AzureFirewallSubnet). Unlike NSGs, which are simple allow/deny rules, Azure Firewall supports FQDN-based filtering (allow traffic to api.example.com regardless of IP), threat intelligence integration that blocks known malicious IPs, TLS inspection for HTTPS traffic, intrusion detection and prevention (in Premium SKU), and centralized policy management through Azure Firewall Policy. Azure Firewall is the right tool when you need application-layer awareness, FQDN filtering, or centralized inspection across multiple VNets.
User Defined Routes (UDRs) override Azure's default system routes to force traffic through a specific next hop. The most common use is hub-and-spoke networking with a central firewall: you create a UDR in spoke subnets with a default route (0.0.0.0/0) pointing to the Azure Firewall private IP as the next hop. All outbound traffic from the spoke then flows through the firewall for inspection before reaching the internet or other VNets. Without UDRs, Azure would route traffic directly using system routes.
Azure Bastion provides browser-based RDP and SSH access to VMs through the Azure portal without requiring a public IP address on the VM or opening RDP (port 3389) or SSH (port 22) ports in an NSG. Bastion is deployed in the AzureBastionSubnet of a VNet and connects to VMs in that VNet or peered VNets. The Standard SKU adds support for connecting to VMs in peered VNets, IP-based connections, and shareable links. Just-in-Time VM Access in Microsoft Defender for Cloud is an alternative: it allows temporary NSG rules that open specific ports for a defined duration upon request.
How to choose the correct answer
NSG: stateful layer 4 filtering by IP, port, protocol. Attached to subnet or NIC. Low-cost, basic traffic control.
NSG priority: lower number = higher priority. First matching rule wins. Default rules at 65000-65500 cannot be deleted.
ASG: logical grouping of VMs referenced in NSG rules. Simplifies rules for dynamic environments.
Azure Firewall: centralized, stateful, FQDN-filtering, threat intelligence. Requires dedicated subnet.
UDR: override system routes to force traffic through NVA or Azure Firewall. Required for hub-spoke inspection.
Azure Bastion: browser-based RDP/SSH, no public IP on VM, no open RDP/SSH port in NSG.
NSG vs Azure Firewall: NSG for subnet/NIC-level filtering. Azure Firewall for centralized, FQDN-aware, policy-based control.