29 November 2026 · 15 min read · Download as PDF
Security groups vs NACLs (network ACLs) in AWS: the full comparison, real rules and exam traps
Security groups are stateful, allow-only and sit on each resource; network ACLs are stateless, allow and deny, and guard a whole subnet. The full comparison table, ephemeral ports, what the defaults allow, rules for a three-tier app, AWS CLI commands, quotas and the Cloud Practitioner exam traps.
Security groups and network ACLs (network access control lists, or NACLs) are the two firewalls built into every Amazon Virtual Private Cloud (VPC). A security group guards a resource such as an Amazon Elastic Compute Cloud (EC2) instance: it is stateful and has allow rules only. A network ACL guards a subnet's boundary, checking traffic as it enters or leaves: it is stateless, can allow and deny, and checks its rules in number order. AWS's advice is to use security groups as your main control and add network ACLs as a coarse, second layer.
This article goes with the video lesson Network security: security groups, NACLs, WAF and Shield (WAF is a web application firewall) in the free AWS Cloud Practitioner course. The video gives you the idea in a few minutes and follows a request from the edge to the database. This page holds what a short video can't: the full comparison table, real rules for a three-tier app, the ephemeral port ranges that trip up NACLs, what the default security group and NACL actually allow, the quotas, the AWS Command Line Interface (AWS CLI) commands, the exam traps and every source.
TL;DR
- Where: a security group is attached to a resource (strictly, to each of its network interfaces). A network ACL is attached to a subnet and covers everything in it.
- State: a security group remembers connections, so replies get back in without a rule. A network ACL doesn't, so replies need their own rule, usually on the ephemeral ports 1024-65535.
- Rules: security groups only allow; anything not allowed is dropped. Network ACLs allow or deny, so they are how you block one IP address.
- Order: a security group looks at all its rules together. A network ACL reads its rules lowest number first and stops at the first match.
- Defaults are opposites: the default network ACL allows everything; a new custom one denies everything. A new security group allows no inbound traffic and all outbound.
- Both are free. Neither one reads web requests: that is AWS WAF's job, on CloudFront, a load balancer, API Gateway or another supported web resource.
Security groups vs NACLs: the full comparison
The first five rows are AWS's own comparison table. The rest come from the same VPC User Guide, the quotas page and the EC2 User Guide.
Security group | Network ACL | |
|---|---|---|
Level of operation | Instance level (each elastic network interface, or ENI) | Subnet level |
Scope | Every resource associated with the group | Every resource in the associated subnets |
Rule type | Allow rules only | Allow and deny rules |
Rule evaluation | All rules, from every group on the resource, before deciding | In ascending rule number; the first match wins |
Return traffic | Allowed automatically (stateful) | Needs its own rule (stateless) |
How many apply | Up to 5 groups per network interface by default (up to 16 on request) | Exactly one per subnet; one NACL can serve many subnets |
Source or destination | An IP address, a CIDR range, a prefix list or another security group | A CIDR range only |
A brand-new one | No inbound rules; one outbound rule allowing everything | Denies all traffic in and out (only the |
The default one | Allows inbound from members of the same group; all outbound | Allows all traffic in and out |
Rule numbers | None; each rule gets an ID such as | 1 to 32766; |
Rules per direction (default quota) | 60 inbound and 60 outbound, counted separately for IPv4 and IPv6 | 20 inbound and 20 outbound, raisable to 40 each |
When you change a rule | Tracked connections carry on until they time out | Takes effect after a short period, and breaks existing connections it now blocks |
Cost | No additional charge | No additional charge |
One thing they share: neither filters traffic to Amazon DNS (the Domain Name System resolver, Route 53 Resolver), Amazon DHCP, EC2 instance metadata, Amazon Elastic Container Service (ECS) task metadata endpoints, the Amazon Time Sync Service, Windows license activation or the reserved IP addresses of the default VPC router. To filter DNS queries, AWS points to Route 53 Resolver DNS Firewall.
Where each one sits
Follow one HTTPS request from a user to a web server in a public subnet. It meets the subnet's network ACL as it enters the subnet, then the web server's security group as it reaches the instance. The reply meets the security group again (already allowed, because the group remembers the request) and then the network ACL as it leaves the subnet, where it needs an outbound rule of its own. Traffic between two instances in the same subnet never crosses the NACL: AWS evaluates NACL rules only when traffic enters or leaves a subnet.

Each layer from the lesson: AWS WAF and AWS Shield at the edge, a network ACL on each subnet, a security group around each tier. Open this diagram in archhy, free, to copy and change it.
Stateful vs stateless, and the ephemeral port trap
When a client opens a connection, it sends from a temporary, high-numbered port called an ephemeral port, and the server replies to that port. A security group tracks the connection, so the reply is let through whatever its rules say. (For Transmission Control Protocol (TCP), User Datagram Protocol (UDP) and ICMP it tracks the connection itself; for other protocols, only the addresses and protocol number, and treats same-type traffic back within 600 seconds as the reply.) A network ACL tracks nothing: the reply is just another packet, and it needs a rule that allows its destination port. AWS's guide puts it plainly: "For every rule that you add, there must be an inbound or outbound rule that allows response traffic."
The client picks the range, so the right NACL rule depends on who is calling:
Client | Ephemeral ports it uses |
|---|---|
Many Linux kernels, including Amazon Linux | 32768-61000 |
Windows Server 2008 and later | 49152-65535 |
Windows through Windows Server 2003 | 1025-5000 |
Elastic Load Balancing (your load balancer) | 1024-65535 |
A NAT (network address translation) gateway | 1024-65535 |
AWS Lambda functions | 1024-65535 |
Two directions to remember:
- Your subnet is the server (users call your web servers): the NACL needs an outbound rule to the clients' ephemeral ports.
- Your subnet is the client (your instances download updates or call an API): the NACL needs an inbound rule for your own instances' ephemeral ports.
You rarely know which client will call a public subnet, and the ranges above are only examples, so AWS's practical advice is to open the whole of 1024-65535 and, if you need to, add lower-numbered deny rules for specific bad ports inside that range.
Defaults: what you get without touching anything
This is where most surprises come from, on the job and on the exam. There are four starting points, and they don't behave alike.
Starting point | Inbound | Outbound |
|---|---|---|
The VPC's default security group (named | All traffic from resources in the same group | All traffic |
A security group you create | Nothing | All traffic |
The VPC's default network ACL | All traffic (rule 100, then | All traffic (rule 100, then |
A network ACL you create | Nothing (only the | Nothing (only the |
- If you launch an EC2 instance without naming a security group, it gets the VPC's default security group. AWS recommends making your own groups instead.
- You can change the default security group's rules but can't delete the group. You can't delete the
*rule of any network ACL. - A subnet you don't associate with a NACL uses the default one, which is why, out of the box, security groups do all the filtering.
- IPv6 gets its own rules (101 in the default NACL,
::/0in the default security group) only when the VPC has an IPv6 range. NACL rules for IPv4 never match IPv6 traffic.
Rule order in a network ACL: a worked example
A NACL stops at the first matching rule, so the numbers matter more than the order you typed them in. Say you want to block one abusive address, 198.51.100.7, from a public web subnet that allows HTTPS from everyone. Its inbound rules:
Rule # | Protocol | Port range | Source | Allow/Deny |
|---|---|---|---|---|
90 | All | All | 198.51.100.7/32 | DENY |
100 | TCP | 443 | 0.0.0.0/0 | ALLOW |
110 | TCP | 1024-65535 | 0.0.0.0/0 | ALLOW |
* | All | All | 0.0.0.0/0 | DENY |
A packet from 198.51.100.7 to port 443 matches rule 90 first and is dropped. Number that deny rule 120 instead and rule 100 matches first, so the "blocked" address gets in. AWS suggests numbering in steps of 10 or 100 so there's room to slot in a rule like 90 later. Rule 110 lets in replies to connections your instances start (updates, API calls), because the NACL won't remember them.
These are only the inbound rules. The same NACL needs outbound rules too: TCP 1024-65535 to 0.0.0.0/0 for the replies to visitors, and TCP 443 to 0.0.0.0/0 if the instances start HTTPS connections of their own. Without them, the outbound * rule drops everything.
The same block is impossible in a security group: it has no deny rules. To keep one address out of a group that allows 0.0.0.0/0, you'd need a NACL (or AWS WAF, if the traffic is web traffic).
Worked example: rules for a three-tier web app
The diagram above, written out as rules. Security groups do the real work, and each tier allows only the tier in front of it by referencing its security group rather than an IP range. That way, new web servers are allowed to reach the database the moment they join the web group, whatever their addresses.
Security group | Inbound rule | Source |
|---|---|---|
| TCP 443 | 0.0.0.0/0 |
| TCP 443 |
|
| TCP 5432 |
|
No outbound rules are needed for the replies: all three groups are stateful. These are inbound rules only: each new group keeps its default "all outbound" rule, so the tiers can still start connections anywhere. To lock that down too, replace it with outbound rules for the paths you need (for example, web-sg to db-sg on 5432). A referencing rule counts as one rule toward the quota, however many instances are in the referenced group.
One gap in this simple version: alb-sg accepts HTTPS from anywhere, so a visitor who finds the load balancer's address can skip CloudFront and AWS WAF. CloudFront's guide shows how to allow only CloudFront, by using its AWS-managed prefix list as the source instead of 0.0.0.0/0.
Now add a NACL as a guard rail on the private database subnet. Say the public subnets are 10.0.0.0/24 and 10.0.1.0/24:
Direction | Rule # | Protocol | Port range | Source or destination | Allow/Deny |
|---|---|---|---|---|---|
Inbound | 100 | TCP | 5432 | 10.0.0.0/24 | ALLOW |
Inbound | 110 | TCP | 5432 | 10.0.1.0/24 | ALLOW |
Inbound | * | All | All | 0.0.0.0/0 | DENY |
Outbound | 100 | TCP | 1024-65535 | 10.0.0.0/24 | ALLOW |
Outbound | 110 | TCP | 1024-65535 | 10.0.1.0/24 | ALLOW |
Outbound | * | All | All | 0.0.0.0/0 | DENY |
The outbound rules carry the database's replies back to the web servers' ephemeral ports. Leave them out and every query times out, even though both security groups are right. That is the classic NACL bug. If someone later opens db-sg to the world by mistake, this NACL still keeps everything but the web subnets out: the backup-layer role AWS describes for NACLs.
Two cautions. A NACL on a load balancer's backend subnet that denies all traffic from 0.0.0.0/0 or from the subnet's own range breaks the load balancer's health checks. And remember the default quota of 20 rules per direction: NACLs are for broad guard rails, not per-application detail.
The AWS CLI commands
The three-tier security group rules (IDs shortened). They assume alb-sg, web-sg and db-sg exist and are attached to the load balancer, the web servers and the database: a rule does nothing until its group is associated with a resource.
aws ec2 create-security-group --group-name web-sg \ --description "Web servers" --vpc-id vpc-0abc# Allow HTTPS to the web servers only from the load balancer's groupaws ec2 authorize-security-group-ingress --group-id sg-0web \ --protocol tcp --port 443 --source-group sg-0alb# Allow PostgreSQL to the database only from the web servers' groupaws ec2 authorize-security-group-ingress --group-id sg-0db \ --protocol tcp --port 5432 --source-group sg-0web# List a group's rules, each with its own sgr- IDaws ec2 describe-security-group-rules \ --filters Name=group-id,Values=sg-0dbA network ACL with the block-one-address rule, then attached to a subnet:
aws ec2 create-network-acl --vpc-id vpc-0abcaws ec2 create-network-acl-entry --network-acl-id acl-0pub \ --ingress --rule-number 90 --protocol -1 \ --cidr-block 198.51.100.7/32 --rule-action denyaws ec2 create-network-acl-entry --network-acl-id acl-0pub \ --ingress --rule-number 100 --protocol tcp \ --port-range From=443,To=443 --cidr-block 0.0.0.0/0 --rule-action allow# Replies to connections the instances start themselvesaws ec2 create-network-acl-entry --network-acl-id acl-0pub \ --ingress --rule-number 110 --protocol tcp \ --port-range From=1024,To=65535 --cidr-block 0.0.0.0/0 --rule-action allow# Replies to visitorsaws ec2 create-network-acl-entry --network-acl-id acl-0pub \ --egress --rule-number 100 --protocol tcp \ --port-range From=1024,To=65535 --cidr-block 0.0.0.0/0 --rule-action allow# Find the subnet's current association, then move it to the new NACLaws ec2 describe-network-acls \ --filters Name=association.subnet-id,Values=subnet-0pubaws ec2 replace-network-acl-association \ --association-id aclassoc-0123 --network-acl-id acl-0pubNote --protocol -1: it means all protocols, and with it the rule covers every port whatever --port-range says. Associating a NACL replaces the subnet's old one, and a new NACL denies everything until it has rules, so add the rules first, including the outbound replies, or you cut the subnet off.
Quotas worth knowing
Quota (default, 28 Nov 2026) | Value |
|---|---|
Security groups per Region | 2,500 (adjustable) |
Rules per security group | 60 inbound and 60 outbound, separately for IPv4 and IPv6 (adjustable) |
Security groups per network interface | 5, adjustable up to 16 |
Rules per group × groups per interface | At most 1,000 |
Network ACLs per VPC | 200 (adjustable) |
Rules per network ACL | 20 inbound and 20 outbound, adjustable to 40 each, "but network performance might be impacted" |
A rule that references a customer-managed prefix list counts as that list's maximum size, so a prefix list with a maximum of 20 entries uses 20 of a group's 60 rules. A rule that references an AWS-managed prefix list (such as CloudFront's) counts as that list's weight.
Changing rules on a live system
- Tightening a security group doesn't cut existing connections. Tracked connections carry on until they time out. To stop traffic immediately, AWS points to a network ACL, which drops packets regardless of what was open before.
- The exception: a flow allowed by a fully open rule (0.0.0.0/0, with all response traffic allowed the other way) isn't tracked, so removing that rule drops it at once. AWS's example is a Secure Shell (SSH) session that dies when you remove an "SSH from anywhere" rule.
- A nearly full NACL: if you delete rules and add new ones in the same change and the additions would go over the quota, the deletions happen and the additions don't. Change one rule at a time and check each.
- Finding the culprit: VPC Reachability Analyzer checks the configuration on the path between two resources and names the component that blocks it, such as a missing NACL rule. VPC Flow Logs record traffic to and from each network interface, marked
ACCEPTorREJECT.
Where AWS WAF, AWS Shield and the rest fit
Security groups and NACLs look at addresses, protocols and ports. They never see the contents of an HTTP request, and they live inside the VPC. The other services in the lesson sit elsewhere:
Service | Where it sits | What it filters |
|---|---|---|
AWS WAF (web application firewall) | On CloudFront, an Application Load Balancer, an API Gateway REST API, AppSync, Cognito, App Runner, Amplify and a few others; not on an EC2 instance or a subnet | HTTP and HTTPS requests: IP, country, headers, SQL injection, cross-site scripting, request rates |
AWS Shield Standard | Everywhere, automatically, at no extra charge | Common network and transport layer DDoS (distributed denial of service) attacks |
AWS Shield Advanced | EC2, load balancers, CloudFront, Route 53 hosted zones, Global Accelerator (paid) | Expanded DDoS protection for those resources: automatic application layer mitigation, detailed attack visibility, the Shield Response Team and service credits for attack-related bill spikes |
AWS Network Firewall | Firewall endpoints in your VPC that traffic is routed through | Stateful inspection and intrusion prevention at the VPC perimeter and between subnets |
AWS Firewall Manager | Across the accounts in your organization | Nothing itself: it applies WAF, Shield Advanced, security group and network ACL policies centrally |
Cloud Practitioner exam traps
The CLF-C02 exam guide names "network ACLs, security groups" under Task Statement 3.5 (AWS network services) and AWS WAF, AWS Shield and AWS Firewall Manager under Task 2.4. The questions are short; the traps are in single words.
- "Stateless" means NACL, "stateful" means security group. If a question says replies are allowed automatically, it's a security group.
- "Block a specific IP address" is a network ACL (or AWS WAF for web traffic), never a security group: security groups have no deny rules.
- "Subnet level" is a NACL; "instance level" is a security group.
- "Evaluated in order, lowest number first" is a NACL. A security group evaluates all its rules.
- The default NACL allows everything. Don't confuse it with a new custom NACL, which denies everything, or with a new security group, which allows no inbound traffic.
- SQL injection or cross-site scripting is AWS WAF, not a security group or NACL.
- DDoS protection at no extra cost is AWS Shield Standard; the Shield Response Team and service credits for attack-related charges are Shield Advanced.
- Who configures them? You do. Under the shared responsibility model, AWS provides security groups and NACLs, and you configure their rules to meet your needs.
FAQ
Do I need network ACLs at all?
Not always. AWS says you can secure instances with security groups alone, and the default NACL lets everything through so security groups do the filtering. Add custom NACLs when you need to deny something (an address, a range, a port) or want a subnet-wide guard rail in case a security group is set up wrong.
If a security group allows traffic and the NACL denies it, what happens?
It's dropped. Traffic must pass both: the NACL as it crosses the subnet boundary, and the security groups on the resource. Either one can stop it.
Can a security group deny traffic?
No. Security groups have allow rules only. Anything not allowed is denied, but you can't write an explicit deny.
Can one subnet have two network ACLs?
No. A subnet has exactly one network ACL at a time; associating a new one replaces the old. One NACL can serve many subnets.
Can one instance have several security groups?
Yes, up to five per network interface by default. Their rules are combined into one set, and traffic is allowed if any rule in any of them allows it.
Do security groups work for things other than EC2?
Yes. Load balancers and Amazon RDS databases take security groups too, as in the three-tier example above. A new RDS DB instance has network access turned off until a security group rule allows it. Reaching it from outside the VPC also needs the instance's Public access setting and an internet gateway on its subnets; the security group still has the final say.
Why does my NACL block replies when the inbound rule looks right?
Because it's stateless. The reply goes to the client's ephemeral port, so the subnet needs an outbound rule for 1024-65535 (or the client's exact range). With a security group you'd never notice, because it tracks the connection.
Do NACLs filter traffic between two instances in the same subnet?
No. NACL rules apply when traffic enters or leaves a subnet, not as it moves within one. Use security groups for that.
Do security groups or NACLs cost anything?
No. AWS charges nothing extra for either.
Keep going
- Watch it: Network security: security groups, NACLs, WAF and Shield, a lesson in the free AWS Cloud Practitioner course with Space Llama.
- Practice Security and Compliance questions in Gazeek Flash, free on the web and on Android.