Network Security Groups
😟 THE PROBLEM
A VM with RDP open to the internet is attacked by bots within hours.
😊 THE SOLUTION
Use NSG rules to allow only the traffic you need.
- Bots guessing passwords on port 3389✓ Deny RDP from the internet
- Database open to all subnets✓ Allow only the web subnet
- No idea what is allowed✓ Clear, prioritised rule list
Quick answer
A network security group (NSG) is a basic firewall for Azure virtual networks. It contains security rules that allow or deny inbound and outbound traffic based on source, destination, port and protocol. You attach an NSG to a subnet or a network interface, and rules are evaluated in priority order.
Exam objective: 2.2.5 Describe virtual networking, including the purpose of Azure virtual networks, subnets, peering, Azure DNS, Azure VPN Gateway, and ExpressRoute. (Skills measured as of July 20, 2026)
Start with a question
Who decides which visitors can knock on your server’s door?
A network security group: a list of rules saying who may come in, on which door (port), and who must be turned away.
Explain it like I’m 10
The technical explanation
| Priority | Name | Port | Source | Action |
|---|---|---|---|---|
| 100 | Allow-HTTPS | 443 | Internet | Allow |
| 200 | Allow-SSH-from-office | 22 | 203.0.113.0/24 | Allow |
| 65500 | DenyAllInBound (default) | Any | Any | Deny |
Real-world business scenario
A small software company
- The problem
- A test VM had RDP open to the internet and was attacked by password-guessing bots within hours.
- What they used
- Removed the open rule, allowed RDP only from the office IP range, and later moved to Azure Bastion.
- Why that choice
- NSG rules limit who can reach management ports.
- The result
- Brute-force attempts stopped immediately.
When to use it and when not to
✓ Use it when…
- Segment subnets (web, app, data).
- Restrict management ports to known IPs.
✕ Think twice when…
- Relying on NSGs alone for advanced inspection. Add Azure Firewall or a WAF where needed.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What is a network security group?
Model answer
It is a list of firewall rules for Azure networks. Each rule allows or blocks traffic based on where it comes from, where it goes, the port and the protocol.
Intermediate How are NSG rules evaluated?
Model answer
By priority. The lowest number is checked first, and processing stops at the first rule that matches. Default rules allow traffic within the VNet and from the Azure load balancer, and deny other inbound traffic from the internet.
Experienced developer NSG or Azure Firewall?
Model answer
NSGs are free, distributed, layer 3 and 4 filters on subnets and NICs, ideal for segmentation. Azure Firewall is a managed, stateful, centralised firewall with FQDN filtering, threat intelligence and logging, used in a hub to control traffic between networks and the internet. Most designs use both.
Test yourself with exercises
3 original practice questions in the AZ-900 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Quick revision
Key points
- NSGs filter traffic with allow and deny rules.
- Rules use source, destination, port, protocol and priority.
- Attach to subnets or network interfaces.
- Lower priority numbers are evaluated first.
Important terminology
- NSG
- A set of allow and deny rules that filter network traffic to and from Azure resources.
- Security rule
- A rule with priority, source, destination, port, protocol and action (allow or deny).
- Priority
- A number from 100 to 4096; lower numbers are processed first.
Common mistakes
- Opening RDP (3389) or SSH (22) to the whole internet.
Exam tips
- "Allow or deny inbound traffic to VMs by port" = network security group.
Five quick revision questions
-
1.What does an NSG do?Show
Allows or denies network traffic with rules.
-
2.Where can you attach an NSG?Show
To a subnet or a network interface.
-
3.Which rule is evaluated first, priority 100 or 200?Show
100.
-
4.Name four rule properties.Show
Source, destination, port and protocol (plus priority and action).
-
5.Is inbound internet traffic allowed by default?Show
No, default rules deny it unless you add an allow rule.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Azure VPN Gateway