Azure Application Security Groups Network Security Groups​

Azure Application Security Groups vs NSGs: How They Work Together

Securing virtual machine network traffic inside Microsoft Azure comes down to two foundational tools: Network Security Groups (NSGs) and Application Security Groups (ASGs). Both show up in nearly every Azure architecture review, yet they carry fundamentally different responsibilities. Confusing them is one of the most common causes of broken or over-permissive network designs.

An NSG is the traffic enforcement engine. It holds discrete security rules that permit or deny packet flow based on source, destination, port, and protocol. An ASG is purely an operational grouping mechanism. It lets administrators collect network interfaces under a single logical workload tag such as Web-ASG or DB-ASG, enforcing nothing on its own.

Understanding how the two interact is essential for building cloud environments that scale. Take a standard enterprise layout with a public-facing web tier, an internal application tier, and a backend database tier. Maintaining firewall rules for that layout with fixed IP addresses becomes unmanageable the moment you add autoscaling or replace an unhealthy instance. Pairing security rules with logical workload grouping is the cleanest way to solve that problem, aligning directly with the micro-segmentation principles described in NIST SP 800-207 on Zero Trust Architecture.

What Is an Azure Network Security Group?

An Azure Network Security Group is a stateful packet filter that inspects and filters traffic for resources inside a Virtual Network (VNet). Microsoft documentation describes NSG rules as filtering on IP addresses, ports, and protocols, which in practice means layers 3 and 4 of the OSI model. Anything that needs application-aware inspection, such as FQDN filtering or URL categories, belongs in a service like Azure Firewall rather than in an NSG.

Every NSG contains your custom security rules plus a set of non-removable default rules. A single NSG supports up to 1,000 security rules according to published Azure subscription and service limits. That capacity is plenty for most designs as long as you avoid writing one rule per individual IP address.

Traffic evaluation relies on a five-tuple: source, source port, destination, destination port, and protocol. When a packet arrives at or leaves a protected resource, the NSG compares those values against its rules and applies the matching action, either Allow or Deny.

Each rule carries a priority value between 100 and 4096. Azure processes rules strictly from the lowest number to the highest. The moment a packet matches a rule, evaluation stops immediately and that rule’s action is enforced. Lower numbers always take precedence.

NSGs are stateful. If an inbound connection is permitted, the return traffic for that flow is allowed automatically, and the reverse holds true for outbound connections. You never need to write a matching rule for response traffic, which keeps rule sets noticeably smaller than they would be on a stateless filter.

How Azure NSG Rules Control Traffic

Evaluation mechanics differ depending on traffic direction. Inbound rules filter packets trying to reach a virtual machine, while outbound rules filter packets leaving it toward internal or external endpoints. The two rule sets function completely independently of each other.

Picture a user connecting to a web server over HTTPS on port 443. The client sends an inbound TCP request targeting port 443, and the NSG scans its inbound rules starting at the lowest priority number. Suppose a rule at priority 150 matches Source: Any, Destination: Web Tier, Port: 443, Protocol: TCP, and Action: Allow. Evaluation ends right there. The packet reaches the VM, and the server’s reply flows back without consulting any outbound rules because the NSG tracks the active session.

If a packet passes every custom rule without a match, it lands on the default system rules. These defaults sit at high priority numbers so your custom rules always get evaluated first. The default inbound rules are:

  • AllowVnetInBound at priority 65000
  • AllowAzureLoadBalancerInBound at priority 65001
  • DenyAllInBound at priority 65500

The default outbound rules mirror that same pattern:

  • AllowVnetOutBound at priority 65000
  • AllowInternetOutBound at priority 65001
  • DenyAllOutBound at priority 65500

The detail that catches many engineering teams off guard is AllowVnetInBound. Because it permits all traffic between resources residing in the same VNet, a freshly deployed web server can reach a database server in a neighboring subnet without writing a single custom rule. Segmentation inside a VNet does not exist by default until you create explicit deny rules to override that baseline behavior.

Where NSGs Are Applied in Azure

An NSG can be associated at two distinct scope levels: a subnet or an individual Network Interface (NIC) attached to a virtual machine.

Attaching an NSG to a subnet means every VM in that subnet inherits the same baseline filtering automatically. Attaching it to a NIC enables host-specific enforcement tailored to a single VM. Subnet-level association serves as the best practical default for most environments because it simplifies auditing, while NIC-level NSGs are best reserved for specific exceptions.

When both levels carry an NSG, evaluation order matters. For inbound traffic, the packet undergoes evaluation by the subnet NSG first, followed by the NIC NSG. For outbound traffic, that order reverses. The NIC NSG evaluates first, and the subnet NSG gets the final say before the packet leaves the boundary. A packet must be explicitly allowed at both layers to get through, which is why troubleshooting blocked connectivity requires checking both NSGs rather than just one.

What Is an Azure Application Security Group?

An Application Security Group is an Azure Resource Manager resource that serves as a logical container for grouping network interfaces by application role. Instead of writing security policy around shifting IP addresses or subnet ranges, you assign VM NICs to an ASG named for their specific function, such as Web-ASG, App-ASG, or DB-ASG. Virtual Machine Scale Sets can also place their instances into an ASG through their network profile, allowing autoscaled instances to join the group automatically at creation time.

An ASG does not filter network packets on its own. It holds no security rules, no open or closed ports, no allow or deny lists, and no routing behavior. Assigning a NIC to an ASG does not alter traffic flow or protect the attached VM until that ASG is explicitly referenced inside an NSG rule.

ASGs carry operational boundaries worth planning around. All NICs assigned to an ASG must reside in the same virtual network as the first NIC added to that group. Published service limits allow 3,000 ASGs per subscription per region and 4,000 IP configurations per ASG, while an individual NIC can belong to up to 20 ASGs. These allocation limits are generous, but platform teams managing hundreds of microservices can reach them, making upfront planning necessary as the environment grows.

Azure Application Security Groups vs NSGs

Treating these two technologies as competing tools leads directly to misconfiguration. They function as complementary pieces of a unified network security design.

An NSG holds the actual filtering logic, including rules, priority rankings, and Allow or Deny directives. It drops unauthorized traffic at the subnet or NIC boundary. An ASG holds only a collection of NIC memberships, acting strictly as a management label for NSG rules to reference.

Their scope of application differs as well. An NSG attaches to subnets or NICs to execute packet filtering for inbound and outbound flows. An ASG attaches exclusively to NICs and serves as a source or destination parameter value inside an NSG rule definition.

The core relationship breaks down cleanly: the NSG defines the security rule, while the ASG identifies the application workloads bound by that rule.

How an ASG Becomes Part of an NSG Rule

Rather than typing a static IP address like 10.0.1.4 or a CIDR block like 10.0.1.0/24 into a rule’s source or destination field, you select an ASG tag instead. When Azure evaluates that rule, it dynamically resolves the ASG to the private IP addresses of every member NIC and applies the rule across all of them simultaneously.

Consider a multi-tier architecture using three groups: Web-ASG for public front-end servers, App-ASG for application logic servers, and Database-ASG for backend database instances. Using these three logical objects, you can govern cross-tier communication without ever tracking or updating the IP address of a single underlying server.

A key practical constraint applies here. If you use ASGs as both the source and destination within a single rule, the member NICs in both groups must live in the exact same virtual network. Microsoft also limits the total number of ASGs that can be referenced across all rules inside a single NSG, making a tidy grouping strategy far more effective than creating a new ASG for every minor workload variation.

Example: Web Servers to Application Servers

To allow the front-end web layer to communicate with the internal middleware layer, you create a single inbound rule on the NSG protecting the application subnet.

The rule Allow-Web-To-App uses priority 100, setting Web-ASG as the source on any source port and App-ASG as the destination on port 8080 over TCP, with the action set to Allow. Every virtual machine assigned to Web-ASG can now reach every virtual machine in App-ASG on TCP port 8080, while all other ports remain restricted.

Example: Application Servers to Database Servers

To enable application servers to query database instances, you add a corresponding inbound rule to the database tier NSG.

The rule Allow-App-To-DB uses priority 110, setting App-ASG as the source on any source port and Database-ASG as the destination on port 1433 over TCP, with the action set to Allow. Only NICs tagged with App-ASG will successfully establish connections to the database instances on that port. Port 1433 serves as the SQL Server default, which can be swapped for 5432 when running PostgreSQL workloads.

Blocking Direct Web-to-Database Traffic

This rule delivers true multi-tier network segmentation. Because the default AllowVnetInBound rule permits direct communication between subnets within the same VNet, an explicit deny rule is mandatory to prevent a web server from talking directly to a database instance.

The rule Deny-Web-To-DB is placed on the database NSG at priority 100, designating Web-ASG as the source on any source port and Database-ASG as the destination on any port across Any protocol, with the action set to Deny. Because priority 100 is lower than the 110 value assigned to Allow-App-To-DB, Azure evaluates the deny directive first. Any direct packet sent from a web node to a database node gets dropped immediately at the network boundary.

Note that the valid priority range for custom NSG rules starts at 100, making 100 the correct starting priority for low-number explicit block rules while keeping priority gaps of 10 between rules for future flexibility.

Why Use ASGs in NSG Rules?

Filtering network traffic with static IP addresses creates a heavy administrative burden in cloud environments. Virtual machines scale in and out, unhealthy nodes get replaced, and IP addresses change continuously. Every infrastructure change forces manual edits to NSG rules, creating opportunities for errors that either disrupt application uptime or open security gaps.

ASGs eliminate this maintenance overhead by decoupling network policy from IP addresses. Security policies follow the workload itself rather than whatever temporary address happens to be assigned to a NIC.

Comparing the two operational models highlights the practical difference:

  • IP-based policy: Allow traffic from 10.0.1.4, 10.0.1.5, and 10.0.1.6 to reach 10.0.2.4 on port 8080. Every time a host joins or leaves the source tier, an administrator must update that IP list manually inside the rule.
  • Application-based policy: Allow traffic from Web-ASG to reach App-ASG on port 8080. When a new VM is provisioned and attached to Web-ASG, Azure updates rule evaluation automatically without requiring any manual edits to the NSG.

There is also a significant governance advantage. A rule written as Web-ASG to App-ASG on port 8080 is completely self-documenting. During compliance audits or internal reviews, an engineer can understand the rule’s intent in seconds, whereas a rule containing a long list of raw IP addresses requires external documentation or spreadsheets to decode. Adoption of ASGs consistently leads to faster rule reviews and prevents rule sprawl when managing large environments.

A Three-Tier Azure Application With ASGs and NSGs

In a production three-tier topology, traffic flows predictably from the external perimeter down through the data persistence layer. NSGs working alongside ASGs enforce boundary isolation at every single hop.

The web tier resides in a dedicated web subnet, with its VM NICs belonging to Web-ASG. The subnet NSG permits inbound public traffic on ports 80 and 443, while restricting outbound connections so they can only target the internal application tier.

The application middleware tier lives in an internal subnet, with its NICs assigned to App-ASG. Its NSG accepts incoming connections exclusively on port 8080 originating from Web-ASG, blocking any direct inbound access from public internet sources.

The database tier sits in a hardened database subnet, with NICs assigned to Database-ASG. Its NSG permits inbound traffic only on database ports such as 1433 for SQL Server or 5432 for PostgreSQL, strictly restricting the source to App-ASG. An explicit deny rule targeting Web-ASG sits at priority 100 above all allow rules.

Outbound internet access requirements also influence subnet architecture. Starting March 31, 2026, newly created Azure virtual networks default to private subnets, meaning VMs in those networks no longer receive implicit outbound internet access. While existing virtual networks remain unaffected, new multi-tier deployments require an explicit outbound path such as an Azure NAT Gateway, Azure Firewall, or an Azure Load Balancer configured with outbound rules. NSGs continue to govern what traffic is permitted, but they no longer rely on implicit outbound access pathways.

Adding a New Server to an Application Tier

When demand increases and autoscaling provisions a new application server, the deployment process attaches the new VM’s NIC to App-ASG during creation.

Because the existing NSG rules already reference App-ASG as a logical destination, the new server instantly inherits every security policy. It can immediately accept connections on port 8080 from the web tier and initiate backend database connections without requiring any manual policy updates.

No one has to edit an NSG rule, reorder priority lists, or update IP address tables. When traffic drops and the server scales in, Azure automatically removes its NIC membership from the group upon deletion. The security policy remains accurate continuously without manual intervention.

NSG Rule Priority, Default Rules, and Traffic Direction

Getting ASG-based rules to evaluate properly requires managing three technical elements: priority values, default system rules, and traffic directionality.

Rule priorities range from 100 to 4096 and are processed sequentially from lowest to highest numerical value. Once a packet matches an active rule, processing stops and all subsequent rules are bypassed. A broad allow rule placed at priority 150 will prevent a more granular deny rule at priority 200 from ever evaluating. A structured approach is to place narrow deny rules at low priority numbers, specific allow rules in the middle range, and avoid overly broad allow directives unless specifically required.

Every NSG includes three default inbound rules and three default outbound rules starting at priority 65000. These default rules permit intra-VNet communication and Azure Load Balancer health probes, allow outbound internet access by default, and drop all other incoming traffic. While you can override these defaults by creating custom rules with lower priority numbers, default rules cannot be removed or deleted from the NSG.

Inbound and outbound rules operate independently of each other. If an application tier NSG allows inbound traffic from Web-ASG, but an outbound rule on the web tier NSG explicitly blocks traffic targeting App-ASG, packets get dropped at the web tier boundary before reaching the application subnet. When troubleshooting unexpected connectivity drops, inspect both directions and both association levels before altering rule logic.

Two platform governance capabilities are also relevant as environments grow larger:

  • Azure Virtual Network Manager security admin rules are evaluated prior to standard NSG rules. This allows central security teams to enforce global guardrails that local application teams cannot override with custom NSGs.
  • NSG Flow Logs visibility options have shifted. Microsoft stopped allowing the creation of new NSG flow logs on June 30, 2025, with full retirement scheduled for September 30, 2027. Migrating monitoring configurations to Virtual Network Flow Logs ensures continuous traffic visibility without monitoring interruptions.

Common ASG and NSG Configuration Mistakes

Most configuration errors stem from misunderstanding how ASGs and NSGs split technical responsibilities.

The most frequent error is assuming that creating an ASG and assigning NICs to it automatically secures those virtual machines. An ASG is merely a logical label, meaning member resources remain fully exposed to default VNet traffic behavior until an NSG rule explicitly references that ASG group.

A second common mistake is attempting to use ASGs across peered virtual networks. All NICs assigned to an ASG must reside in the same VNet, and rules referencing ASGs as both source and destination require both groups to share that exact VNet. VNet peering connections do not extend ASG membership boundaries across VNets. Cross-VNet filtering policies require IP prefixes, service tags, or centralized routing controls like Azure Firewall or Azure Virtual Network Manager.

A third mistake involves mixing static IP rules alongside ASG references for the same server workload. Combining both mechanisms creates ambiguity regarding which rule actually governs active flows, eroding the maintenance benefits that make ASGs valuable in the first place.

A fourth common mistake is overlooking the default AllowVnetInBound rule. Building allow rules between tiers without adding explicit deny rules leaves all other intra-VNet communication wide open. Implementing explicit block rules is required to achieve real network micro-segmentation.

When to Use Application Security Groups With NSGs

Application Security Groups deliver maximum value in dynamic, multi-tier environments where server workloads scale frequently or where multiple virtual machines execute the same application role. They fit microservices topologies, autoscaling web application pools, and any cloud architecture requiring strict segmentation without managing complex lists of IP addresses.

For small, static environments consisting of only one or two fixed virtual machines, ASGs may add unnecessary administrative abstraction. Simple setups benefit from standard NSG rules using native subnet prefixes or built-in service tags like VirtualNetwork, Internet, or AzureLoadBalancer.

A clear operational rule of thumb applies: if you regularly update NSG rules because underlying IP addresses changed, you have outgrown static rules and should implement ASGs. If server counts remain fixed and network rules rarely change, keeping the configuration simple with standard NSGs remains an effective approach.

Azure ASGs and NSGs: The Practical Difference

Network Security Groups operate as the enforcement layer where network access policies are defined, prioritized, and executed. They inspect inbound and outbound packets to permit or drop connections based on explicit rule criteria.

Application Security Groups function as logical tags that allow those NSG rules to refer to application workloads by their operational role rather than by static IP addresses.

Together, NSGs deliver the firewall enforcement engine, while ASGs provide a manageable structure that scales automatically as cloud infrastructure evolves.