Filtering Traffic with Security Groups and Network ACLs
This lesson explains how security groups and network ACLs filter traffic at different layers with different behaviour, on which many connectivity and security questions turn.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish stateful security groups from stateless network ACLs.
- Design rules for each tier.
- Block an IP range with a network ACL.
Security groups
A security group is a stateful virtual firewall attached to network interfaces (instances, load balancers, RDS, Lambda in a VPC, endpoints). It contains only allow rules for inbound and outbound traffic; anything not allowed is denied. Because it is stateful, responses to allowed traffic are allowed automatically regardless of rules. Rules can reference CIDRs, prefix lists or other security groups, for example "allow 5432 from the application tier's security group", which keeps rules correct as instances change. The default outbound rule allows all traffic. Changes apply immediately, but existing tracked connections may persist until they end.
Network ACLs
A network ACL is a stateless filter applied to all traffic entering and leaving a subnet. Rules are numbered and evaluated in order from the lowest number; the first match decides, and a final * rule denies everything else. NACLs support both allow and deny rules, so they can block a specific IP range. Because they are stateless, return traffic must be allowed explicitly: an inbound HTTPS rule needs a matching outbound rule for ephemeral ports (1024-65535) to reach clients, and outbound connections need inbound ephemeral rules for replies. The default NACL allows all traffic; a newly created custom NACL denies all traffic until rules are added.
The following diagram shows a deny rule placed before the allow rules.

Security group or network ACL?
Designing rules
Use security groups as the primary control, chained by reference between tiers, and NACLs as a coarse subnet-level guard, for example denying a malicious IP range or isolating a data subnet. Security group VPC associations allow one security group to be used in several VPCs in the same Region, and shared security groups work in VPC sharing. Network Access Analyzer and Reachability Analyzer verify that rules produce the intended paths.
Writing rules
Blocking an attacking IP range
A web tier receives abusive traffic from 203.0.113.0/24. Security groups cannot express a deny, and removing the existing allow from 0.0.0.0/0 would block all users. The operator adds NACL rule 90 on the public subnets: deny all traffic from 203.0.113.0/24, numbered lower than the existing allow rule 100 for HTTPS. For HTTP-level filtering with rate limiting, an AWS WAF IP set and rate-based rule on the ALB would be the better long-term control.
Which is stateful: a security group or a network ACL?
Show answer
A security group. Return traffic is allowed automatically, whereas a network ACL needs explicit rules for it.
Exam Tips
Remember for the exam
- Security groups are stateful, allow-only and attached to ENIs.
- NACLs are stateless, ordered, allow and deny, at the subnet level.
- NACLs need explicit ephemeral port rules for return traffic.
- Block a specific IP with a NACL deny or WAF, not a security group.
- Reference security groups by ID between tiers.