Network Security Group or Application Security Group: Which is Right for Your Azure Environment?
Azure Network Security Groups (NSGs) and Application Security Groups (ASGs) are often discussed as though an administrator must choose one or the other. That is the wrong design question. An NSG contains the rules that allow or deny network traffic; an ASG identifies a set of network interfaces that those rules can refer to. A workload may need an NSG without an ASG, but an ASG does not filter a single packet on its own.
The distinction matters most when a virtual network moves beyond a few static machines. Address-based rules may look manageable on day one and become fragile when application servers are replaced, scaled or moved between subnets. Grouping machines by their actual role can make the policy easier to understand, but the network administrator must still decide where rules are enforced and which flows are permitted.
A network security group is a collection of inbound and outbound rules attached to an Azure subnet, a network interface, or both. Each rule specifies a direction, protocol, source, destination, source and destination ports, an allow-or-deny action, and a numeric priority. Azure evaluates matching rules in priority order; the lower priority number wins. Custom rule priorities normally run from 100 through 4096, before the built-in default rules at priorities around 65000.
For example, a rule allowing TCP 443 from a known application subnet to a private API’s subnet is an NSG rule. An explicit rule denying inbound TCP 3389 from the internet is also an NSG rule. The policy can refer to CIDR ranges, individual IPs, certain service tags or ASGs as appropriate. The security group is evaluated as a stateful filter: return traffic for an established allowed connection does not usually require a separate reverse-direction allow rule. It is not a web application firewall, and it does not inspect the contents of an encrypted HTTP request.
Azure gives every NSG default rules. Those defaults include inbound access within the VirtualNetwork tag and a deny-all inbound rule, as well as outbound virtual-network and internet allowances followed by a deny-all outbound rule. The built-in defaults cannot be deleted, but more-specific custom rules take precedence. It is therefore unsafe to assume that creating an NSG automatically isolates every application tier from every other tier: broad virtual-network flows may still match an allow rule unless a deliberate higher-priority restriction exists.
Placement also matters. A subnet NSG and a NIC NSG can both affect the same flow. Administrators must inspect the effective rules at the relevant network boundaries rather than reading one rule list and assuming that it describes the entire path. NSGs control whether a packet is permitted on an evaluated path; they do not create network routes, configure DNS, or make a service listen on a particular port.
An application security group is a logical collection of Azure network interfaces. Instead of writing a rule such as “allow TCP 443 from 10.20.3.14, 10.20.3.18 and 10.20.3.22,” an administrator can place the appropriate application NICs in an ASG named AsgApp and use that group as a source in an NSG rule. The NSG still performs the filtering; the ASG simply supplies membership information when the rule is evaluated.
This indirection pays off when the application tier changes. A replacement VM can be assigned to the same ASG, making the existing role-based rule usable without editing each IP-address entry. Membership still needs to be maintained through the provisioning process; an ASG does not discover a workload’s business role simply from its VM name or operating system.
There are important boundaries. The network interfaces in a single ASG must belong to the same Azure virtual network. When an NSG rule refers to ASGs at both ends, the groups’ NICs must be in that same virtual network. An ASG is not a cross-subscription identity service, a DNS group or a substitute for designing connections between separate VNets. For cross-network segmentation, IP prefixes, routing, service tags and higher-level firewall controls may be needed in addition to NSGs.
| Design question | NSG | ASG |
|---|---|---|
| Does it allow or deny traffic? | Yes, through prioritized rules | No, it only identifies interfaces |
| Where is it applied? | To a subnet or NIC | Membership on NICs, referenced by rules |
| What problem does it solve? | Enforcing permitted network flows | Keeping rule targets tied to workload roles |
| Can it work by itself? | Yes, using address-based rules | No, an NSG must use it in a rule |
| Typical change event | New permitted port or network boundary | Adding or replacing a VM in an application tier |
The most useful design is often a combination: an NSG provides the security boundary and ASGs help express which application tiers may communicate across it. Describing the choice as NSG or ASG conceals that relationship.
Consider an internal business application with web, application and database virtual machines in a single VNet. The web tier accepts HTTPS from an approved front-end path, the application tier accepts requests from the web tier, and a database accepts connections only from the application tier. Create AsgWeb, AsgApp and AsgDb and assign the correct NICs as the machines are provisioned. Apply NSGs to the intended subnets or NICs and write narrowly scoped rules that reference the groups.
An example policy might allow the required HTTPS flow into AsgWeb; allow TCP 443 from AsgWeb to AsgApp; and allow TCP 1433 from AsgApp to AsgDb if the database really is a SQL Server listening on that port. That final protocol and port must be verified against the actual database service, not copied from a sample. The application tier should not receive direct internet access merely because an easy default rule happens to permit it.
Role-based allows are only half the design. Explicit higher-priority deny rules or carefully structured subnet restrictions may be needed to override the default virtual-network allowance for flows that are not part of the approved application contract. Rule priority must be checked for conflicts: a broad allow at a lower number can silently defeat a later, more specific deny. Document the source, destination, protocol, port, direction and reason for every important rule, then test an expected allow and an expected deny.
A small environment without scale changes may be simpler with an NSG and a few explicit address ranges; adding ASGs would create naming and provisioning work without a real benefit. For a growing three-tier application, however, ASG membership can be a useful abstraction. The metric is operational clarity, not how many Azure security objects appear in the resource group.
Many NSG troubleshooting incidents are actually path problems. If a source VM cannot reach an API, first establish the destination IP and port, then inspect the effective route, the applicable NSG rules and finally the destination service. An allow rule cannot repair an absent route or the wrong DNS answer. Likewise, a working route does not make a denied port accessible.
Peered networks are a common source of confusion. VNet peering can establish a private network route between VNets, but security policies, DNS and the return path still require separate validation. Do not assume that an ASG defined in one VNet can simply group NICs in another, or that a peering relationship automatically makes every flow safe to allow. Where a hub firewall or network virtual appliance performs inspection, user-defined routes and that device’s policies become additional enforcement points.
Applying an NSG to both a subnet and a NIC can be legitimate, but it increases the number of effective decisions that an engineer must explain. Start with a consistent boundary model, use exceptions sparingly, and record why an individual NIC needs treatment that differs from its subnet. A configuration that is technically possible may still be needlessly hard for the on-call engineer to audit.
When a rule change appears ineffective, use evidence from the actual source and destination instead of adding another broad allow. Azure Network Watcher provides tools for investigating connection reachability, effective security rules and IP flow decisions. Check the five-tuple—source address, source port, destination address, destination port and protocol—against the rules that apply to the relevant direction. Then verify whether the expected NIC is a member of the ASG referenced by the rule.
Common failure patterns include a rule with the right port but the wrong direction, a rule whose priority is lower than a broader matching rule, an ASG with missing NIC membership, a subnet-level allow still blocked at another relevant boundary, and an application with no listener on the permitted port. Authentication or TLS errors may arise after the network has already allowed the connection; changing an NSG at that point is unlikely to solve them.
For ongoing visibility, prefer Azure virtual network flow logs for new deployments. Microsoft has stopped new NSG flow-log creation and scheduled the older NSG flow-log feature to retire on September 30, 2027. Existing older logging configurations should be assessed and migrated deliberately rather than presented as the recommended new setup. Logs are observations about network flows, not a reason to disable a restrictive rule or a substitute for application-level telemetry.
An NSG filters on network-level attributes. It cannot decide that an HTTPS request contains a malicious input, apply URL-path-specific access policy, inspect arbitrary TLS payloads or replace identity authorization in an application. A design that requires centrally inspected egress, advanced threat controls or application-layer filtering may need Azure Firewall, an appropriately configured web application firewall, or another security service. These controls complement NSGs rather than making them interchangeable.
Keep the security boundaries distinct: identities and application permissions govern who may perform an action; NSGs govern permitted network paths; ASGs help represent which interfaces belong to an application role; routing chooses the next hop; and monitoring supplies evidence when reality diverges from the diagram. Neither an NSG nor an ASG guarantees that a workload is secure on its own.
Use NSGs when you need to permit or deny traffic to a subnet or network interface. Add ASGs when grouping VMs by their application roles makes those rules clearer and less vulnerable to IP-address churn. Use both when a workload’s traffic contract is naturally expressed between tiers, and avoid an ASG if the same job can be performed more clearly by a small, stable set of NSG rules.
Before treating the design as finished, prove one allowed flow and one blocked flow, inspect effective rules and routes, check ASG membership, and make sure the results remain correct after replacing a VM. The best Azure network policy is one an engineer can still understand during a production incident—not the one with the longest list of security objects.