Azure Firewall vs NSG vs WAF: which to pick
A network security group (NSG) filters packets by address, port and protocol on a subnet or network interface. Azure Firewall is a central, stateful firewall service that adds FQDN filtering, threat intelligence and (in Premium) intrusion detection. A Web Application Firewall (WAF) inspects HTTP and HTTPS requests for attacks such as SQL injection and cross-site scripting. The decision rule: name what has to be inspected. Ports and IP ranges means NSG; outbound domain names or one central control point means Azure Firewall; web attacks means WAF. They do not replace each other, and most real designs use all three.
Triage by what the requirement says
| The scenario says | Choose | Why |
|---|---|---|
| Allow only TCP 443 to a subnet; block RDP from the internet | NSG | Layer 3 and 4 allow and deny rules, no extra cost |
Allow outbound traffic only to *.contoso.com | Azure Firewall | Application rules filter by FQDN; an NSG only knows IPs and service tags |
| One place to log and control traffic of many VNets | Azure Firewall (hub VNet) | Central deployment, managed through firewall policy |
| Block SQL injection or cross-site scripting | WAF | Only the WAF reads the HTTP request |
| Block traffic to known malicious IPs and domains | Azure Firewall | Threat intelligence filtering |
| Detect attack signatures inside allowed traffic | Azure Firewall Premium | Signature-based IDPS |
| Per-VM micro-segmentation inside a subnet | NSG with application security groups | Rules at the NIC level |
What each service really is
NSG. A list of priority-ordered allow and deny rules, free of charge, attached to a subnet or NIC. It is stateful and has no concept of a domain name, a URL or an HTTP header. The evaluation logic has its own guide: NSG rule evaluation.
Azure Firewall. A managed, stateful firewall that inspects east-west and north-south traffic. Microsoft’s overview lists three SKUs: Basic (for small and medium-sized businesses, threat intelligence in alert mode only), Standard (layer 3 to 7 filtering and threat intelligence feeds) and Premium (adds signature-based IDPS and TLS inspection). Rules come in three kinds, and the firewall always processes DNAT rules first, then network rules, then application rules, regardless of collection priority. Within a type, lower priority number wins, and a match is terminating. The default is deny. Firewall Manager applies one firewall policy to many firewalls.
WAF. Not a standalone appliance but a feature you switch on for a supported service: Application Gateway, Application Gateway for Containers, Azure Front Door, and (in preview at the time of writing) Azure CDN. It works at layer 7, so the traffic must pass through one of those services first. The Azure Firewall documentation says it directly: Azure Firewall does not apply application rules to inbound connections, so inbound HTTP and HTTPS filtering belongs to a WAF.
Worked example: a small web shop
A shop runs a web tier and a database tier in one VNet.
- The public site sits behind Application Gateway with WAF enabled, in prevention mode. Requests with injection patterns are rejected before they reach the VMs.
- The web subnet has an NSG: allow 443 from the Application Gateway subnet, deny everything else inbound. The database subnet NSG allows 1433 only from the web subnet.
- All outbound traffic from both subnets is routed by a user-defined route to Azure Firewall in a hub VNet. An application rule allows only the payment provider’s domain and the OS update domains. Everything else is denied by default.
Remove the WAF and an injection attack passes the NSG, because port 443 is legitimately open. Remove the firewall and a compromised VM can call any server on the internet whenever the subnet still has an outbound path (a NAT gateway, a public IP, or default outbound access on older non-private subnets), because the default NSG rule AllowInternetOutBound permits it. Remove the NSGs and VMs in the same subnet talk to each other freely. Each layer closes a gap the others leave open. For zero-trust framing of this layering, see Zero Trust explained.
Which exams test this
| Exam | How it appears | Covered on this site |
|---|---|---|
| SC-900 | Capabilities of Microsoft security solutions: describe Azure Firewall, WAF and NSGs as core infrastructure security services, at a describe-what-it-does level (same objectives in the outline that applies from October 21, 2026) | Microsoft security solutions explained |
| SC-500 | Secure storage, databases and networking: implement NSGs and application security groups, and implement and configure Azure Firewall. Secure compute: implement and configure Azure Web Application Firewall | Storage, databases and networking, Secure compute |
| AZ-305 | Design infrastructure solutions: recommend a solution to optimize network security and a load-balancing and routing solution, for example central inspection in a hub or Application Gateway or Front Door with WAF | Infrastructure explained |
| AZ-104 | Implement and manage virtual networking: create NSGs and application security groups and evaluate effective rules. Only the NSG side of this comparison; Azure Firewall and WAF are not AZ-104 objectives | Virtual networking explained |
How exam questions are built around it
The trap is almost always one product answering a need that belongs to another layer. Watch for these words.
- “SQL injection”, “cross-site scripting”, “OWASP”, “web application”: WAF. A firewall or NSG is a distractor.
- “FQDN”, “domain name”, “URL filtering”, “threat intelligence”, “centralized across subscriptions”: Azure Firewall.
- “Port”, “source IP range”, “subnet”, “least cost”: NSG.
- “Inbound HTTP/S to a web app”: do not pick Azure Firewall for filtering the requests. The WAF is the answer, with Azure Firewall at most doing DNAT.
- “TLS inspection”, “IDPS”: Premium SKU. Standard does not have them.
- Layer 7 load balancing with protection: Application Gateway with WAF (regional) or Front Door with WAF (global). Azure Load Balancer has no WAF; see the AZ-305 infrastructure guide.
Practice questions
Question 1. A company hosts a public web application behind Azure Application Gateway. A security review shows that requests containing SQL injection patterns reach the web servers. The fix must work for all web servers behind the gateway without changing application code. What should you do?
- A. Add an NSG rule that denies SQL traffic on port 443
- B. Deploy Azure Firewall Standard in front of the gateway and add application rules
- C. Enable Web Application Firewall on the Application Gateway
- D. Increase the Application Gateway instance count
Show answer
Answer: C
A Web Application Firewall inspects HTTP and HTTPS requests and can be enabled on Application Gateway, which protects every backend centrally. An NSG filters by address and port, so it cannot see SQL patterns inside a request on an allowed port. Azure Firewall does not apply application rules to inbound connections. Moving to a larger gateway size does not add inspection.
Question 2. Virtual machines in several spoke virtual networks must be able to reach only an approved list of external domain names. All outbound traffic must be logged in one place and the allowed list must be managed centrally. Which solution meets the requirement?
- A. An NSG on every spoke subnet with outbound rules
- B. Azure Firewall in a hub virtual network with user-defined routes from the spokes
- C. Web Application Firewall on Azure Front Door
- D. A service endpoint on each spoke subnet
Show answer
Answer: B
Azure Firewall in a hub network, with user-defined routes sending spoke traffic to it, provides FQDN-based application rules, central logging and a single policy. NSGs cannot filter by domain name and would have to be managed per subnet. A WAF protects inbound web applications, not outbound traffic from VMs. A service endpoint only connects a subnet to specific Azure services.
Go deeper
- What is Azure Firewall? (SKUs and capabilities)
- Azure Firewall rule processing logic
- Introduction to Azure Web Application Firewall (supported services)
- Related guides: NSG rule evaluation, VNets, subnets and peering, Private endpoint vs service endpoint, Azure load balancing options