
Security Groups vs Network ACLs: The AWS Firewall Rules That Finally Made Sense
A beginner-friendly comparison of AWS Security Groups and Network ACLs, including how they control traffic, where they operate, and when to use each one.
π Security Groups vs Network ACLs: The AWS Firewall Rules That Finally Made Sense
When I started learning AWS networking, two terms kept appearing:
Security Groups
Network ACLs
Network ACLs
Both control network traffic.
So naturally, I wondered:
Why does AWS need two different security controls?
After learning how they work, the difference became much clearer.
The easiest way I now remember it is:
Security Groups protect resources. Network ACLs protect subnets.
Let's break that down.
ποΈ First, Where Do They Sit?
Imagine this simple architecture:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
π Internet
β
βΌ
ββββββββββββββββ
β VPC β
β β
β Public Subnetβ
β β
β ββββββββ β
β β EC2 β β
β ββββββββ β
β β² β
β β β
β Security β
β Group β
ββββββββββββββββThe Security Group is associated with the resource, such as an EC2 instance.
A Network ACL operates at the subnet level.
So the traffic path can be thought of as:
1
2
3
4
5
6
7
8
9
10
11
12
13
Internet
β
βΌ
Network ACL
β
βΌ
Subnet
β
βΌ
Security Group
β
βΌ
EC2This distinction is fundamental.
π‘οΈ What Is a Security Group?
A Security Group acts like a virtual firewall for AWS resources such as EC2 instances.
For example, I might create rules like:
1
2
3
4
5
6
7
8
9
Inbound Rules
HTTPS
Port: 443
Source: 0.0.0.0/0
SSH
Port: 22
Source: My trusted IPThis means:
- HTTPS traffic can reach the instance.
- SSH is restricted to my trusted IP.
- Other inbound traffic isn't allowed by the security group's inbound rules.
π Security Groups Are Stateful
This is one of the most important differences.
Security Groups are stateful.
Imagine my EC2 instance receives a request:
1
2
3
4
5
6
7
8
9
Client
β
β HTTPS Request
βΌ
EC2
β
β Response
βΌ
ClientIf the inbound request is allowed by the Security Group, the response traffic is automatically allowed as part of that established connection.
I don't need to create a separate rule specifically for the response traffic.
That's what stateful means in this context.
π§ What Is a Network ACL?
A Network Access Control List (NACL) operates at the subnet level.
Instead of protecting one specific EC2 instance, it controls traffic entering or leaving a subnet.
For example:
1
2
3
4
5
6
7
8
9
10
11
VPC
β
βββ Public Subnet
β β
β βββ NACL
β β
β βββ EC2
β
βββ Private Subnet
β
βββ NACLA subnet has an associated Network ACL.
This provides another layer of network control.
π’ NACL Rules Use Rule Numbers
NACL rules are evaluated in order.
For example:
1
2
3
4
5
6
7
8
9
10
Rule #100
Allow TCP 443
Source: 0.0.0.0/0
Rule #200
Allow TCP 80
Source: 0.0.0.0/0
Rule #*
Deny everything elseAWS evaluates the rules starting with the lowest rule number.
The first matching rule is applied.
This means the order of NACL rules matters.
π NACLs Are Stateless
This is another major difference.
Network ACLs are stateless.
If I allow inbound traffic, I also need to consider the corresponding outbound traffic.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Client
β
β Request
βΌ
NACL
β
βΌ
EC2
β
β Response
βΌ
NACL
β
βΌ
ClientThe inbound and outbound traffic are evaluated separately.
This is different from Security Groups.
βοΈ Security Group vs NACL
Here's the comparison that helped me remember the difference:
| Feature | Security Group | Network ACL |
|---|---|---|
| Operates at | Resource level | Subnet level |
| Stateful | β Yes | β No |
| Supports explicit deny | β No | β Yes |
| Rules | Allow rules | Allow + Deny |
| Rule order | Doesn't use numbered evaluation order | Lowest number evaluated first |
| Controls | Traffic to/from associated resources | Traffic entering/leaving subnet |
| Common use | Protect EC2 and other resources | Additional subnet-level traffic control |
π§ A Simple Analogy
I found this analogy useful.
Imagine an apartment building.
π’ Network ACL = Building security
The building security decides:
"Who is allowed into this part of the building?"
It operates at a broader level.
πͺ Security Group = Apartment door
The apartment door controls:
"Who can access this particular apartment?"
It's much more specific.
So:
1
2
3
4
5
6
7
8
9
10
Building Security
β
βΌ
Subnet
β
βΌ
Apartment Door
β
βΌ
ResourceThis isn't a perfect technical analogy, but it helped me understand the different scopes.
π Real-World Example
Suppose I'm building a web application.
My architecture looks like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
π Internet
β
βΌ
Load Balancer
β
βΌ
ββββββββββββββββββββ
β Public Subnet β
β β
β Network ACL β
β β β
β βΌ β
β Load Balancer β
ββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββ
β Private Subnet β
β β
β Network ACL β
β β β
β βΌ β
β EC2 β
β Security Group β
ββββββββββ¬ββββββββββ
β
βΌ
DatabaseI can use Network ACLs as a subnet-level control and Security Groups as a more specific resource-level control.
π Security Groups Can Reference Other Security Groups
Another useful feature is that Security Groups can reference other Security Groups in certain AWS networking scenarios.
For example:
1
2
3
4
5
6
7
8
9
Load Balancer SG
β
β allows HTTPS
βΌ
Application SG
β
β allows database traffic
βΌ
Database SGInstead of relying entirely on IP addresses, I can express relationships between application components.
For example:
Allow the database to receive traffic from the application servers' Security Group.
This makes large architectures easier to manage.
β οΈ Common Beginner Mistakes
β Mistake 1: Thinking Security Groups support explicit deny rules
They don't.
Security Groups use allow rules, and traffic that isn't allowed is denied.
β Mistake 2: Forgetting that NACLs are stateless
Inbound and outbound traffic are evaluated independently.
β Mistake 3: Thinking a public subnet automatically means every resource is publicly accessible
It doesn't.
Routing, IP addressing, Security Groups, and other configuration still matter.
β Mistake 4: Opening SSH to the entire internet unnecessarily
A rule such as:
1
2
Port: 22
Source: 0.0.0.0/0allows SSH attempts from anywhere.
For administrative access, a narrower trusted source is generally preferable when practical.
β Mistake 5: Using complicated NACL rules without understanding the traffic flow
Because NACLs are stateless and rule ordering matters, troubleshooting them can become difficult if the rules aren't carefully designed.
π How I Think About Troubleshooting Now
If an EC2 instance can't communicate with something else, I don't immediately blame the application.
I walk through the network:
1
2
3
4
5
6
7
8
9
1. Is the resource in the correct subnet?
β
2. What does the route table say?
β
3. Does the Network ACL allow the traffic?
β
4. Does the Security Group allow the traffic?
β
5. Is the resource configured correctly?This approach gives me a much better way to troubleshoot AWS networking.
π― My Mental Model
After learning both concepts, I remember them like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
VPC
β
ββββββΌβββββ
β Subnet β
ββββββ¬βββββ
β
Network ACL
β
βΌ
βββββββββββ
βResource β
ββββββ¬βββββ
β
Security GroupNetwork ACL β subnet-level control
Security Group β resource-level control
And the biggest difference:
Security Groups are stateful and allow-based, while Network ACLs are stateless and support both allow and deny rules.
π Final Takeaway
AWS networking initially looked like a collection of unrelated terms:
VPC β Subnet β Route Table β Internet Gateway β Security Group β NACL
But once I started thinking about where traffic enters, where it goes, and which layer controls it, the architecture became much easier to understand.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article