Back to blog

Blog

AWS Security Group vs NACL: Which One Blocks What?

AWS security group vs NACL, explained: stateful vs stateless, allow vs deny, the ephemeral port trap, Terraform examples and a VPC review checklist.

AWS security group vs NACLUpdated 11/17/2026Shafi Khan

AWS Security Group vs NACL: Which One Blocks What?

AWS security group vs NACL comes down to five differences: security groups protect individual resources, allow traffic only, and are stateful; network ACLs protect whole subnets, can allow and deny, and are stateless. In practice, security groups do the precise work, and NACLs are an optional, coarse guardrail around a subnet.

The rest is for when it matters: the health check times out, the app can't reach the database, and the incident channel is arguing about which firewall ate the packet. Below: the exact rules, the ephemeral port trap, Terraform for both layers and a review checklist.

AWS security group vs NACL: the comparison table

AWS publishes the canonical comparison in its Amazon VPC infrastructure security docs. Here it is, with the practical consequence of each row added:

CharacteristicSecurity groupNetwork ACLWhat it means for you
Level of operationInstance level (attached to network interfaces)Subnet levelSGs follow the resource; NACLs follow the subnet it lives in
ScopeAll resources associated with the groupAll resources in the associated subnetsOne NACL change can hit every workload in a tier
Rule typeAllow rules onlyAllow and deny rulesOnly NACLs can say "block this CIDR"
Rule evaluationAll rules evaluated before decidingNumbered rules evaluated in ascending order, first match winsRule order matters in NACLs and doesn't exist in SGs
Return trafficAutomatically allowed (stateful)Must be explicitly allowed (stateless)NACLs need ephemeral port rules; SGs don't

Two more facts worth pinning to the wall:

  • Defaults are opposite in spirit. A new security group starts with no inbound rules and one outbound rule allowing all traffic, per the AWS docs on creating security groups. The default NACL allows all inbound and outbound traffic: it has a catch-all * deny rule, but its allow-all rule 100 matches first.
  • Every subnet has exactly one NACL. A NACL can be associated with many subnets, but a subnet can only have one NACL at a time; associating a new one replaces the old association (see AWS's network ACL basics page).

AWS is also refreshingly direct about priority: you can secure instances using only security groups, and NACLs are an additional layer of defense. So if you're asking "do I have to use NACLs?", the official answer is no.

→ Paste your security group rules into the free Security Group Rule Visualizer and see the exposure at a glance

Stateful vs stateless firewall in AWS: how a packet actually travels

Picture a request from the internet to an instance in a public subnet. The route table sends it to the subnet. The subnet's NACL checks it on the way in. Then the instance's security group checks it at the network interface. The response goes back out the same way: security group first, then NACL.

Request:   Internet -> IGW -> [NACL inbound]  -> [SG inbound]  -> instance:443
Response:  instance -> [SG outbound: skipped, stateful] -> [NACL outbound] -> client:ephemeral port

That second line is the whole story.

  • Security groups are stateful. If inbound traffic is allowed, the response is allowed to leave regardless of outbound rules. If the instance starts a connection, the response is allowed back in regardless of inbound rules. AWS spells this out in its security groups overview.
  • NACLs are stateless. They keep no memory of the request, so the response is just another packet that must match an outbound rule. AWS also notes that NACL rules are evaluated when traffic enters and leaves the subnet, not as it's routed within a subnet. Two instances in the same subnet never touch the NACL.

There's also traffic NACLs don't see at all. Per AWS, network ACLs don't filter traffic to and from Amazon DNS, Amazon DHCP, EC2 instance metadata, ECS task metadata endpoints, Windows license activation, Amazon Time Sync Service and the reserved VPC router addresses. So "I'll block DNS exfiltration with a NACL" is not a plan. It's a vibe.

Want the boundaries drawn rather than described? The VPC design explainer covers how subnets, route tables and tiers fit together.

→ Map trust boundaries and exposure on your actual diagram with Security Posture

The NACL ephemeral ports trap

Here's the classic failure. You lock down a public subnet NACL: inbound 443 allowed, outbound 443 allowed, everything else denied. The site goes dark. Why?

Because the response doesn't go to port 443. It goes to the client's ephemeral port, a high port the client's OS picked when it opened the connection. Your outbound rule for 443 doesn't match it, the catch-all deny does, and the response dies at the subnet edge.

The range depends on who the client is. From AWS's custom network ACL docs:

ClientEphemeral port range
Many Linux kernels, including Amazon Linux32768-61000
Windows Server 2008 and later49152-65535
Windows through Windows Server 20031025-5000
Elastic Load Balancing1024-65535
NAT gateway1024-65535
AWS Lambda1024-65535

It cuts both ways:

  • Serving traffic (clients connect to you): your NACL needs an outbound rule to the clients' ephemeral ports.
  • Making requests (your instance calls an API or downloads packages): your NACL needs an inbound rule for return traffic on your instance's ephemeral ports.

For public-facing subnets with unknown clients, AWS's practical advice is to open 1024-65535 and, if you need to block specific ports in that range, add deny rules earlier in the table than the broad allow. Since NACLs evaluate in ascending order and stop at the first match, a deny at rule 90 beats an allow at rule 140.

Also: number your rules in gaps of 10 or 100. AWS recommends it, and future-you inserting an emergency deny rule at 2 a.m. will be grateful.

→ Turn a messy rule set into a readable port, source and exposure matrix with the Security Group Rule Visualizer

Can a security group deny traffic? When you actually need a NACL

Short answer: no. Security groups have allow rules only. Anything not allowed is implicitly dropped, but you can't write "allow everything except 198.51.100.0/24". That's the NACL's job.

So when is a custom NACL worth the operational cost? Real talk, less often than tutorials suggest. Reach for one when:

  1. You need an explicit deny. Blocking a known bad CIDR at the subnet edge, ahead of every security group in that subnet.
  2. You want a hard tier boundary that survives a sloppy SG change. A data-subnet NACL that only admits the database port from the app subnets means a too-broad security group on the database still can't be reached from the public tier.
  3. Separation of duties. A central network team owns NACLs, application teams own their security groups. Each layer is a check on the other.

And when not to: if you're tempted to replicate every security group rule in a NACL, stop. You've built two firewalls that must change in lockstep, and NACLs have tight default quotas. Per the Amazon VPC quotas page, a network ACL defaults to 20 inbound and 20 outbound rules (adjustable up to 40 each, with a possible performance impact). Security groups default to 60 inbound and 60 outbound rules per group and 5 groups per network interface, with rules-per-group multiplied by groups-per-interface capped at 1,000.

Security groups also have a superpower NACLs don't: referencing other security groups. A rule with another security group as the source allows traffic from the private IPs of every resource associated with that group, as described in AWS's security group rules docs. No CIDRs to maintain, no drift when Auto Scaling replaces an instance. NACLs can only match CIDR blocks.

→ Stress-test your tier boundaries for spoofing, tampering and exposure with Threat Analyzer

Terraform: security groups and a data-tier NACL

Here's the pattern most teams should default to: security groups chained by reference for precise access, plus one custom NACL guarding the data subnets. The CIDRs match the subnet grid from our AWS three-tier architecture diagram guide: app subnets 10.0.10.0/24 and 10.0.11.0/24, data subnets 10.0.20.0/24 and 10.0.21.0/24.

First, the security group edge. The database accepts PostgreSQL only from the app tier's security group:

resource "aws_security_group" "db" {
  name   = "three-tier-db"
  vpc_id = aws_vpc.main.id
}

resource "aws_vpc_security_group_ingress_rule" "db_from_app" {
  security_group_id            = aws_security_group.db.id
  referenced_security_group_id = aws_security_group.app.id
  ip_protocol                  = "tcp"
  from_port                    = 5432
  to_port                      = 5432
  description                  = "PostgreSQL from app tier"
}

No egress rule needed for responses: security groups are stateful. Now the NACL, which has to spell out both directions:

resource "aws_network_acl" "data" {
  vpc_id     = aws_vpc.main.id
  subnet_ids = [aws_subnet.data_a.id, aws_subnet.data_b.id]

  tags = {
    Name = "data-tier"
  }
}

locals {
  app_cidrs = {
    a = "10.0.10.0/24"
    b = "10.0.11.0/24"
  }
}

# Inbound: PostgreSQL from each app subnet
resource "aws_network_acl_rule" "data_in_pg" {
  for_each       = local.app_cidrs
  network_acl_id = aws_network_acl.data.id
  rule_number    = each.key == "a" ? 100 : 110
  egress         = false
  protocol       = "tcp"
  rule_action    = "allow"
  cidr_block     = each.value
  from_port      = 5432
  to_port        = 5432
}

# Outbound: responses back to the app tier's ephemeral ports
resource "aws_network_acl_rule" "data_out_ephemeral" {
  for_each       = local.app_cidrs
  network_acl_id = aws_network_acl.data.id
  rule_number    = each.key == "a" ? 100 : 110
  egress         = true
  protocol       = "tcp"
  rule_action    = "allow"
  cidr_block     = each.value
  from_port      = 1024
  to_port        = 65535
}

A few notes a principal architect would ask about:

  • Inbound and outbound rule numbers are separate lists, so reusing 100 and 110 on both sides is fine.
  • Everything else hits the * deny rule, which you can't modify or delete. That's the point: nothing from the public subnets reaches the data tier, even if a security group is misconfigured.
  • Don't mix inline ingress/egress blocks on aws_network_acl with standalone aws_network_acl_rule resources. Pick one style per NACL, or Terraform will fight itself on every plan.
  • Test in a non-production VPC first, and account for anything else the data tier talks to (backup agents, admin paths). A subnet-wide deny is a big hammer.

Need the subnet ranges first? The free CIDR Subnet Calculator carves non-overlapping blocks per tier and AZ.

→ Keep these rules from silently diverging from the design with Drift Detector

Debugging: is it the security group or the NACL?

When traffic disappears, VPC Flow Logs are your witness. AWS's flow log record examples walk through exactly this case, and the pattern is easy to remember:

What you see in flow logsLikely culprit
One REJECT record for the inbound request, nothing elseThe security group (or NACL inbound rule) never let the request in
ACCEPT for the request, then REJECT for the response in the reverse directionA stateless NACL rule dropped the return traffic, often missing ephemeral ports
ACCEPT in both directionsIt's not the network layer; check the app, TLS or health check config

AWS's own example: a ping is allowed in by both the security group and the NACL, the security group lets the reply out because it's stateful, and the NACL drops the reply because it has no outbound ICMP rule. One ACCEPT, one REJECT. Flow logs don't name the rule that dropped the packet, so confirm by reading both rule sets.

Quick triage tip: same-subnet traffic skips NACLs entirely, so if two instances in one subnet can't talk, look at the security groups.

For broader exposure reviews, the network exposure best practices guide covers what to look for beyond individual rules.

→ Turn a flaky network path into a reviewable finding with Security Posture

AWS security group best practices: the review checklist

Run this before a design review or after any incident that involved "who opened that port?":

  • Every security group rule has a description that says why it exists (descriptions can be up to 255 characters, so there's room)
  • App and data tiers use security group references, not CIDR ranges, for internal traffic
  • No inbound 0.0.0.0/0 or ::/0 rule exists except on internet-facing load balancers or edge components, and each one is intentional
  • Admin ports (SSH 22, RDP 3389) and database ports are never open to the internet
  • Outbound "allow all" is a decision someone made, not a default nobody revisited
  • Custom NACLs, where used, allow return traffic on the right ephemeral ports in both directions
  • NACL deny rules sit at lower numbers than the allow rules they override
  • NACL rules are numbered with gaps so emergency rules can be inserted
  • Nobody is using NACLs to "block" DNS, instance metadata or Time Sync traffic (they can't)
  • Rule counts are within quota, especially NACLs at the default of 20 per direction
  • The architecture diagram labels every arrow with port, protocol and the rule that allows it
  • VPC Flow Logs are enabled on the subnets you'd need to debug during an incident

If the last item about the diagram made you wince, you're not alone. The diagram nobody updated since 2023 is the most common security finding that never makes it into a ticket.

→ Generate a full architecture review checklist for your stack with the free builder

Key takeaways

  • Security groups: instance level, allow-only, all rules evaluated together, stateful. They're your primary, precise control.
  • NACLs: subnet level, allow and deny, first match by ascending rule number, stateless. They're an optional, coarse guardrail.
  • Stateless means ephemeral ports. Most "NACL broke my app" incidents are missing return-traffic rules.
  • Only NACLs can deny. Use them for explicit blocks and hard tier boundaries, not to mirror every security group rule.
  • Reference security groups instead of CIDRs for internal traffic; it survives scaling and reads like the diagram.
  • Flow logs tell you which side dropped the packet: one REJECT suggests the inbound path, ACCEPT then REJECT suggests a stateless NACL on the way back.

→ See how your current rules expose each tier with the Security Group Rule Visualizer

FAQ

What is the difference between a security group and a NACL in AWS?

A security group works at the instance level, allows traffic only and is stateful, so return traffic is allowed automatically. A network ACL works at the subnet level, can allow and deny, evaluates numbered rules in ascending order and is stateless, so return traffic must be allowed explicitly.

Can a security group deny traffic?

No. Security groups only have allow rules; anything not allowed is dropped. To explicitly deny an IP range, use a network ACL deny rule numbered lower than the allow rules it should override.

Do I need NACLs if I already use security groups?

Not strictly. AWS documents that you can secure instances using only security groups and add network ACLs as an additional layer of defense, for example a hard boundary around data subnets or an explicit deny list.

Why does my NACL block responses even though inbound traffic is allowed?

Because NACLs are stateless. Responses are checked against the outbound rules and go to the client's ephemeral port, not the service port. If that range isn't allowed outbound, the response is dropped.

What ephemeral port range should a NACL allow?

It depends on the client: AWS documents 32768-61000 for many Linux kernels, 49152-65535 for Windows Server 2008 and later, and 1024-65535 for Elastic Load Balancing, NAT gateways and Lambda. For mixed clients, AWS suggests 1024-65535 with any port-specific deny rules placed earlier.

→ Bring STRIDE thinking to your network boundaries with the free STRIDE Threat Checklist

Draw the firewall rules, don't just write them

Security groups and NACLs are easy to explain and easy to get wrong, mostly because the rules live in a console tab while the architecture lives in someone's head. When every arrow on the diagram carries its port, protocol and rule, reviews catch the open database port before an attacker does.

Architecto gives you the diagram and the review lens in one place: sketch or generate the topology, then inspect exposure and trust boundaries with Security Posture before the rules ship.

→ Start free and review your VPC's security boundaries in Architecto

FAQ

Questions readers ask before they act on this page.

What is the difference between a security group and a NACL in AWS?

A security group works at the instance level, allows traffic only and is stateful, so return traffic is allowed automatically. A network ACL works at the subnet level, can allow and deny, evaluates numbered rules in ascending order and is stateless, so return traffic must be allowed explicitly.

Can a security group deny traffic?

No. Security groups only have allow rules; anything not allowed is dropped. To explicitly deny an IP range, use a network ACL deny rule numbered lower than the allow rules it should override.

Do I need NACLs if I already use security groups?

Not strictly. AWS documents that you can secure instances using only security groups and add network ACLs as an additional layer of defense, for example a hard boundary around data subnets or an explicit deny list.

Why does my NACL block responses even though inbound traffic is allowed?

Because NACLs are stateless. Responses are checked against the outbound rules and go to the client's ephemeral port, not the service port. If that range isn't allowed outbound, the response is dropped.

What ephemeral port range should a NACL allow?

It depends on the client: AWS documents 32768-61000 for many Linux kernels, 49152-65535 for Windows Server 2008 and later, and 1024-65535 for Elastic Load Balancing, NAT gateways and Lambda. For mixed clients, AWS suggests 1024-65535 with any port-specific deny rules placed earlier.

Related reading

Keep moving through the architecture workflow.

Free tool

Security Group Rule Visualizer

See inbound and outbound exposure patterns across security group rules before a review turns into line-by-line spreadsheet work.

aws security group analyzerfirewall rule visualizersecurity group matrix

Free tool

CIDR / Subnet Calculator

Model VPCs, landing zones, and segmented networks with a deterministic subnet calculator built for architects and platform teams.

subnet calculatorvpc cidr planningnetwork range calculator

Free tool

STRIDE Threat Checklist

Walk through spoofing, tampering, repudiation, information disclosure, denial of service, and elevation risks using a deterministic system model.

threat modeling checkliststride templatesecurity review checklist

Guide

What vpc design means in AWS Architecture

What vpc design means in AWS Architecture with technical review guidance, practical artifacts, and a workflow path into diagrams, documentation, and architecture governance.

aws architecturevpc designaws reference architecture

Guide

Security Architecture best practices for network exposure

Security Architecture best practices for network exposure with technical review guidance, practical artifacts, and a workflow path into diagrams, documentation, and architecture governance.

security architecturenetwork exposureapplication security architecture

Comparison

Architecto vs Cloudcraft

Architecto vs Cloudcraft with a workflow-first comparison across diagrams, architecture review, technical documentation, and code-adjacent implementation evidence.

cloudcraft alternativearchitecto vs cloudcraftbrand comparison
AWS Security Group vs NACL: Which One Blocks What? | Architecto