Security operations

What Is a Stateful Firewall? How Stateful Inspection Works

A stateful firewall remembers every connection passing through it, so it can tell a legitimate reply from an unsolicited packet. Here is how the state table works and where stateful inspection fits.

Cysoro Security TeamPublished · 8 min read
SECURITY OPERATIONS Stateful Firewall A firewall with a memory: every connection tracked, every reply checked. STATE TABLE 192.168.1.14 : 51234-> 93.184.216.34 : 443ALLOW 10.0.0.8 : 49821-> 172.217.14.110 : 443ALLOW 203.0.113.77 : 60112-> 10.0.0.5 : 22DROP No matching session — dropped. SYN → SYN-ACK → ACK → ESTABLISHED CYSORO
Quick answer

A stateful firewall is a firewall that tracks the state of active network connections in a state table and uses that context to decide which packets to allow. When a computer inside the network starts a connection, the firewall records it, then automatically allows the replies. Packets that do not belong to a known, approved connection are checked against the firewall rules or dropped.

Key takeaways

  • A stateful firewall remembers active connections in a state table, so replies to approved sessions pass without extra rules.
  • It works at OSI Layers 3 and 4, tracking IP addresses, ports, protocols and TCP flags such as SYN, ACK and FIN.
  • It cannot inspect application-layer content or authenticate users, so pair it with a next-generation firewall or intrusion prevention for full coverage.

Every firewall decides which packets may cross your network boundary. A stateless firewall makes that decision one packet at a time, with no memory. A stateful firewall remembers: it keeps a live record of every connection and uses that context to judge each packet.

What is a stateful firewall?

A stateful firewall is a firewall that tracks the state of active network connections and uses that context to decide which packets to allow through. It operates mainly at OSI Layers 3 and 4, the network and transport layers.

When a device inside your network opens a connection — say, your laptop loading a website — the firewall records that connection in its state table. When the website replies, the firewall recognizes the reply as part of an approved session and lets it in. A packet that arrives uninvited, with no matching entry in the state table, is checked against the firewall's rules and usually dropped.

This approach is also called stateful inspection or dynamic packet filtering. Check Point developed the technique in the early 1990s, and it has since become the industry standard: most modern network firewalls, host firewalls and cloud security groups are stateful by default.

The two ideas that matter are state and context. State is where a connection sits in its lifecycle — new, established, or closing. Context is the metadata around it: source and destination IP addresses, port numbers, the protocol, and sequence numbers. Together they let the firewall tell a genuine reply from a packet that merely claims to be one.

How does a stateful firewall work?

A stateful firewall works in four steps: it watches a connection start, records it in the state table, checks every later packet against that table, and removes the entry when the connection ends.

How stateful inspection decides on a packet1Watch it startfirewall sees thefirst packet of anew connection2Record the stateIPs, ports, protocoland state go intothe state table3Check each packetmatches a knownsession? Allow it.No match? Apply rules.4Remove on closeFIN or RST ends thesession; the entryis deletedA packet with no matching state entry is treated as a new connection and judged by the rules.
The four steps of stateful inspection. Illustration by Cysoro.

The TCP three-way handshake

For TCP traffic, the firewall follows the three-way handshake: SYN, SYN-ACK, ACK. It logs the connection when it sees the SYN, confirms it when the handshake completes, and then tracks flags such as FIN and RST to know when the session ends.

If a packet arrives with flags that make no sense for the recorded state — for example, an ACK for a connection that never started — the firewall can drop it. This is how stateful inspection catches many spoofed or malformed packets that a stateless filter would wave through.

What about UDP?

UDP has no handshake and no built-in connection state, so the firewall improvises. When it sees the first outbound UDP packet, it creates a temporary state entry and allows replies for a short timeout. If no further traffic arrives before the timeout, the entry expires. This pseudo-state is what lets DNS lookups and video calls work through a stateful firewall.

What does the state table hold?

Each entry records the source and destination IP addresses, source and destination ports, the protocol, and the current state of the connection. Fortinet's guide notes that the firewall also tracks sequence numbers and flags, which helps it spot packets that do not fit the session they claim to belong to.

The table is live and constantly updated. Entries are added as connections open and removed as they close or time out. On a busy network this table can hold tens or hundreds of thousands of entries, which is why stateful firewalls need more memory than stateless ones.

Stateful vs stateless firewall: what's the difference?

A stateless firewall judges each packet in isolation against a fixed rule list. A stateful firewall remembers the connections those packets belong to, so it can allow replies automatically and spot packets that do not fit any known session.

Stateful firewallStateless firewallNext-generation firewall
Remembers connectionsYes — state tableNo — each packet aloneYes, plus application state
OSI layersLayers 3 and 4Layers 3 and 4Layers 3 to 7
Return trafficAllowed automaticallyNeeds a separate ruleAllowed automatically
Speed and costModerateFastest, cheapestSlowest, most expensive
Sees inside packetsHeaders and some payloadHeaders onlyFull deep packet inspection
Knows the userNoNoYes — user identity
Typical usePerimeter, cloud security groups, host firewallsRouter ACLs, high-speed edgesEnterprise perimeter, data centers

The practical difference shows up in rule writing. With a stateless firewall, allowing web browsing means opening the full range of high-numbered ports for replies — a wide hole. A stateful firewall needs only one outbound rule; the state table handles the replies, and nothing else gets in. That is the core security win.

Stateless filtering still has a place. It is simple, fast, and cheap, so it suits router access lists and very high-throughput edges where tracking every connection would be too costly. Palo Alto Networks notes that stateless firewalls can suit small businesses with little sensitive data, while stateful inspection fits environments where security needs are more complex.

What are the benefits of a stateful firewall?

The main benefits are stronger security with simpler rules, automatic handling of return traffic, and better visibility into what is actually happening on the network.

  • Fewer, simpler rules. You write rules for the direction that starts a connection. The state table takes care of the rest, so rule sets stay short and easier to audit.
  • Unsolicited traffic is dropped by default. A packet that does not match a known session has no business arriving, and the firewall treats it that way.
  • Session-aware decisions. Because it follows the TCP handshake and tracks flags, it can reject malformed or out-of-sequence packets that look harmless to a header-only filter.
  • Logging with context. Logs can show whole sessions rather than isolated packets, which makes incident investigation far easier.
  • Efficient use of resources. Once a session is approved, later packets are checked against the state table instead of being re-evaluated against the full rule set, which keeps throughput high.

What are the limitations of a stateful firewall?

A stateful firewall cannot see application-layer threats, cannot authenticate users, and needs more processing power and memory than a stateless filter. It is one layer, not a complete defense.

  • No application-layer inspection. It cannot reliably detect malware in a download, a phishing page, or an attack on a web application. Those threats travel inside connections the firewall has already approved.
  • No user authentication. It judges traffic by addresses and ports, not by who is behind the keyboard. A stolen laptop on the office network looks like a legitimate user.
  • State table exhaustion. Attackers can flood a firewall with half-open connections to fill its state table, a classic SYN flood. Modern firewalls mitigate this with timeouts and SYN cookies, but the risk is real.
  • Encrypted traffic is opaque. With most web traffic now encrypted, a stateful firewall at Layers 3 and 4 cannot see what is inside the session at all.
  • Configuration mistakes still hurt. A stateful firewall with an overly permissive rule set is no safer than a stateless one. Misconfiguration remains the most common firewall failure.

For a small business, the practical answer is layering. Keep the stateful firewall as your perimeter, then add the controls that cover its blind spots — for example, the checks in our small business cybersecurity checklist.

Where are stateful firewalls used?

Stateful firewalls are used almost everywhere traffic crosses a boundary: at the network perimeter, inside cloud platforms as security groups, on individual servers as host firewalls, and in home routers.

Cloud security groups are a good example. When you open port 443 to a virtual server in AWS or Azure, the security group is stateful: replies to connections your server started are allowed back automatically, and you never write a rule for them. Network ACLs in the same clouds are stateless, which is why they need explicit rules in both directions.

Host firewalls such as Windows Defender Firewall and Linux nftables are also stateful. They track the connections of the applications running on that one machine, which is why a laptop can browse the web safely on a coffee-shop network.

On a home network, the router's firewall is stateful too. That is why devices on your Wi-Fi can reach the internet but nobody on the internet can reach them uninvited — the same principle explained in our guide to how to secure your Wi-Fi.

How do you configure a stateful firewall well?

Start with a default-deny policy, allow only the traffic your business actually needs, and review the rules on a schedule. NIST SP 800-41, the US government's firewall guidance, states the core principle plainly: firewalls should block all traffic that has not been expressly permitted.

Five rules for a healthy stateful firewall1Default denyBlock everything, then allow only what the business needs2Least privilegeOpen specific ports to specific hosts, never wide ranges3Log and reviewCheck denied traffic and rule hit counts every month4Protect the management planeAdmin access only from trusted networks, with MFA5Test before you pushA bad rule can cut off the whole office
Five configuration rules that keep a stateful firewall effective. Illustration by Cysoro.
  1. Default deny in both directions. Block all inbound traffic that is not expressly allowed, and filter outbound traffic too, so malware cannot phone home freely.
  2. Give every rule an owner and a reason. Rules without a ticket reference or an expiry date become permanent by accident. Review them at least twice a year.
  3. Log denied traffic and read it. A sudden rise in denied packets often means a scan or a misconfigured service. Silence in the logs is not proof of safety.
  4. Lock down the management interface. The firewall's admin page should never face the internet, and admin accounts need multi-factor authentication.
  5. Test changes in a maintenance window. One wrong rule can cut off remote workers or a payment system, so test first and keep a rollback plan.
Watch the state table sizeIf your firewall slows down under load, check the state table. A flood of half-open connections can exhaust it, and the fix is usually shorter timeouts for incomplete sessions plus SYN flood protection, not a bigger box.

Stateful firewall vs next-generation firewall: which do you need?

A next-generation firewall (NGFW) starts with stateful inspection and adds application awareness, user identity, intrusion prevention and deep packet inspection. Choose a plain stateful firewall for simple perimeters and cloud security groups; choose an NGFW when you need to control applications and inspect encrypted traffic.

For a small business with a handful of servers, a stateful firewall plus endpoint protection and good email security is often enough. Larger organizations, or any business handling sensitive data, usually need the NGFW's application-layer controls — for example, blocking file uploads to personal cloud storage, or stopping known exploit patterns before they reach a server.

Either way, the firewall is one control among many. It does not replace patching, backups, or training people to spot the messages that get past every filter, like the targeted emails in our spear phishing guide.

The bottom line

A stateful firewall earns its place by remembering. By tracking every connection in a state table, it lets legitimate replies through automatically while dropping traffic nobody asked for — with far simpler rules than a stateless filter needs.

Its limits are just as clear: it works at Layers 3 and 4, so it cannot judge what is inside an approved connection or who is using it. Treat it as the foundation of your network defense, then layer application-aware controls on top.

You can check what your own network exposes to the internet with our free what is my IP tool.

Frequently asked questions

What is a stateful firewall in simple terms?

It is a firewall with a memory. When a device inside your network starts a connection, the firewall writes it down in a state table. Replies to that connection are allowed back in automatically, while packets that do not match any known connection are blocked or checked against the rules.

What is the difference between a stateful and a stateless firewall?

A stateless firewall judges every packet on its own against a fixed rule list, with no memory of earlier packets. A stateful firewall remembers active connections, so it can tell whether a packet is part of a session it already approved. Stateful inspection is more secure but uses more memory and processing power.

What is a state table in a firewall?

The state table is the firewall's live record of every active connection: source and destination IP addresses and ports, the protocol, and the connection's current state, such as established or closing. The firewall checks each packet against this table before deciding what to do with it.

Does a stateful firewall inspect packet contents?

It inspects packet headers and some payload information to track connection state, but it is not a deep packet inspection engine. It generally cannot detect malware inside web traffic or phishing, which is why organizations pair it with next-generation firewalls or intrusion prevention systems.

Is a stateful firewall enough for a small business?

For most small businesses, yes as a starting point. The firewall built into a business router, a cloud security group, or the host firewall on a server is usually stateful, and combined with a default-deny policy it blocks most unsolicited inbound traffic. Add application-layer protection for web and email threats.

What is stateful inspection vs deep packet inspection?

Stateful inspection tracks connection state and context at the network and transport layers. Deep packet inspection goes further, examining the full contents of packets at the application layer to find malware, data leaks or banned applications. Next-generation firewalls combine both.

Can a stateful firewall handle UDP traffic?

Yes, with a workaround. UDP has no handshake or connection state, so the firewall creates a pseudo-state: it records the first outbound UDP packet and allows replies for a short timeout window, then removes the entry when the timeout expires.

What attacks can a stateful firewall stop?

It stops unsolicited inbound connections, port scans that probe closed ports, and many session-based attacks, because packets that do not belong to an approved session are dropped. It does not stop attacks that ride inside an approved connection, such as a malicious download over HTTPS.

Sources

  1. Fortinet — What Is a Stateful Firewall?
  2. Palo Alto Networks — What Is a Stateful Firewall?
  3. TechTarget — Stateful inspection
  4. NIST — SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against Fortinet's and Palo Alto Networks' stateful firewall guides and NIST SP 800-41 Rev. 1, Guidelines on Firewalls and Firewall Policy.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free