Security Group and Network ACL in AWS (original) (raw)

Last Updated : 2 Jun, 2026

In AWS, securing your network involves two main layers of protection: Security Groups (SGs) and Network Access Control Lists (NACLs). Both work like firewalls, but they protect different parts of the VPC and behave differently.

region

The main difference between them is based on Stateful and Stateless filtering.

1. Security Groups (Stateful)

A Security Group acts as a virtual firewall for your EC2 instances and other AWS resources like RDS, Lambda, and ELB.

**Level: Instance Level

**Behavior: Stateful

**Rules: Allow Only

**Usage: Primary Defense

**Example: If you allow outbound internet access from an EC2 instance to download updates, the returning traffic is automatically permitted without adding extra inbound rules.

2. Network ACLs (Stateless)

A Network ACL (NACL) acts as a firewall for an entire subnet.

**Level: Subnet Level

**Behavior: Stateless

**Rules: Allow and Deny

**Usage: Secondary Defense

**Example: If you allow inbound HTTP traffic on port 80, you must also allow outbound response traffic, otherwise, the communication will fail.

Comparison Matrix

**Feature **Security Group **Network ACL (NACL)
**Scope Instance Level (EC2, RDS, ENI) Subnet Level
**State Stateful (Return traffic auto-allowed) Stateless (Return traffic must be allowed)
**Rule Types Allow rules only Allow and Deny rules
**Default Rule Deny All (Implicit) Allow All (Default NACL) / Deny All (Custom NACL)
**Order All rules evaluated before decision Processed in Number Order (Lowest first)
**Blocking Cannot explicitly block an IP Can explicitly DENY an IP

Working of Network ACL ( NACL )

Network ACLs (NACLs) evaluate the traffic entering and leaving the subnet in your VPC (Virtual Private Cloud). They process rules in sequential order, starting from the lowest numbered rule, to determine whether the traffic should be allowed or denied.

If a packet matches an allow rule, it is permitted; if it matches a deny rule, it is blocked. When no rule matches, the default deny action is applied, helping enforce security policies and protect AWS infrastructure from unauthorized access and potential threats.

Managing Subnet Traffic Using Network ACLs in AWS

The following are the steps that guides you in controlling the traffic to subnets using the Network ACLs:

Network ACL Rules

Network ACL rules control the traffic entering and leaving a subnet in a VPC. Rules are processed from the lowest to highest rule number, and the first matching rule is applied.

Network ACLs and Other AWS Services

Network ACLs work with other AWS services to improve security and network management by providing an additional layer of protection at the subnet level alongside Security Groups. They also integrate with AWS CloudFormation and AWS CLI, allowing users to automate the deployment and management of network access controls within AWS infrastructure.

Scenario: Web Server in a Public Subnet

Security Group Configuration

Since Security Groups are stateful, the response traffic is automatically allowed back to the user.

NACL Configuration

Since NACLs are stateless, outbound ephemeral ports must be explicitly allowed; otherwise, the response traffic will be blocked.

Best Practices