← Back to Questions
AWS

Difference between Security Groups vs NACL?

Learn Difference between Security Groups vs NACL? with simple explanations, real-time examples, interview tips and practical use cases.

Security Groups and Network ACLs (NACLs) are the two main security layers in AWS VPC networking.

Both are used to control traffic, but they operate at different levels and behave differently.

Simple Definition: Security Groups act as instance-level virtual firewalls, while Network ACLs (NACLs) act as subnet-level firewalls.

High-Level Architecture

Internet
    |
Network ACL (Subnet Level)
    |
Subnet
    |
Security Group (Instance Level)
    |
EC2 Instance
    

Main Difference

Feature Security Group NACL
Level Instance Level Subnet Level
State Stateful Stateless
Allow Rules Yes Yes
Deny Rules No Yes
Rule Evaluation All rules evaluated Rules processed in order
Applies To EC2 Instances Entire Subnet

What is a Security Group?

A Security Group is a virtual firewall attached to AWS resources such as EC2 instances.

Security Group Architecture

Internet
    |
Security Group
    |
EC2 Instance
    

Main Responsibilities

  • Control inbound traffic
  • Control outbound traffic
  • Protect EC2 instances

Example Security Group Rules

Type Protocol Port Source
SSH TCP 22 192.168.1.0/24
HTTP TCP 80 0.0.0.0/0
HTTPS TCP 443 0.0.0.0/0

Stateful Behavior of Security Groups

Security Groups are stateful.

What Does Stateful Mean?

If inbound traffic is allowed, the response traffic is automatically allowed.

Example

User Request → Allowed
Response → Automatically Allowed
    

Characteristics of Security Groups

  • Stateful firewall
  • Supports only allow rules
  • Attached directly to instances
  • Easy to manage

Advantages of Security Groups

  • Simplified management
  • Automatic return traffic handling
  • Fine-grained instance security

Limitations of Security Groups

  • No deny rules
  • Only instance-level protection

What is a Network ACL (NACL)?

Network ACL (Access Control List) is a subnet-level firewall controlling traffic entering and leaving a subnet.

NACL Architecture

Internet
    |
Network ACL
    |
Subnet
    |
EC2 Instances
    

Main Responsibilities

  • Protect entire subnet
  • Control inbound traffic
  • Control outbound traffic

Example NACL Rules

Rule # Type Protocol Port Allow/Deny
100 HTTP TCP 80 Allow
110 SSH TCP 22 Deny

Stateless Behavior of NACL

NACLs are stateless.

What Does Stateless Mean?

Both inbound and outbound rules must be explicitly configured.

Example

Inbound HTTP Allowed
BUT
Outbound Response Must Also Be Allowed
    

Characteristics of NACL

  • Stateless firewall
  • Supports allow and deny rules
  • Applied at subnet level
  • Rules evaluated sequentially

Advantages of NACL

  • Subnet-wide protection
  • Supports deny rules
  • Additional security layer

Limitations of NACL

  • Complex rule management
  • Manual return traffic rules required

Security Groups vs NACL Architecture

Internet
    |
NACL (Subnet Security)
    |
Subnet
    |
Security Group (Instance Security)
    |
EC2 Instance
    

Rule Processing Difference

Security Group Rule Processing

All Rules Evaluated
If Match Found → Allow
    

NACL Rule Processing

Rules Checked in Number Order
First Match Wins
    

Example of NACL Rule Evaluation

Rule # Action
100 Allow HTTP
110 Deny All

Traffic Flow Example

User Request
      |
NACL Check
      |
Security Group Check
      |
EC2 Instance
    

Real-World Example

Security Group Usage

Web Server Security Group
    |
Allow:
- HTTP 80
- HTTPS 443
- SSH 22
    

NACL Usage

Subnet NACL
    |
Deny Suspicious IP Ranges
Allow Corporate Traffic
    

Production Security Architecture

Internet
   |
Network ACL
   |
Public Subnet
   |
Load Balancer
   |
Security Group
   |
Application Server
    

Best Practices

  • Use Security Groups as primary firewall
  • Use NACLs for subnet-level protection
  • Implement least privilege access
  • Avoid opening unnecessary ports
  • Use deny rules in NACLs for suspicious traffic

Common Mistakes

  • Forgetting outbound NACL rules
  • Opening all ports to the internet
  • Using overly permissive CIDR ranges
  • Misunderstanding stateful vs stateless behavior

When to Use Security Groups

  • Instance-level protection
  • Application-specific rules
  • Simple firewall management

When to Use NACLs

  • Subnet-level restrictions
  • Blocking malicious IP ranges
  • Extra network security layer

Enterprise Banking Architecture

Internet
    |
NACL
    |
DMZ Public Subnet
    |
Load Balancer
    |
Private Application Subnet
    |
Security Group
    |
Application Servers
    

Interview Answer

Security Groups and Network ACLs are AWS VPC security mechanisms.

Security Groups operate at the instance level and act as stateful firewalls, meaning return traffic is automatically allowed.

NACLs operate at the subnet level and act as stateless firewalls, requiring explicit inbound and outbound rules.

Security Groups support only allow rules, whereas NACLs support both allow and deny rules.

Quick Summary Table

Feature Security Group NACL
Level Instance Subnet
State Stateful Stateless
Deny Rules No Yes
Management Simpler More Complex
Main Use Instance Security Subnet Security

Useful Internal Links

Final Conclusion

Security Groups and NACLs provide layered security in AWS VPC networking.

Security Groups protect individual instances, while NACLs protect entire subnets.

Understanding their differences is critical for building secure, scalable, and enterprise-grade AWS infrastructures.

Why this AWS question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.