System Atlas
the atlas
NET · Networking7 minApplied

What is a firewall

The gatekeeper that decides which packets are allowed to cross a network boundary.

the gist

A firewall inspects traffic crossing a boundary and allows or denies it against a set of rules. It comes in increasing sophistication: packet filtering judges each packet by IP, port and protocol; stateful inspection tracks whole connections; and application-layer firewalls (including WAFs) understand the actual request payload. Firewalls run at the network edge and on individual hosts, and default-deny plus layered inspection is the standard posture.

ANALOGY // A firewall is airport security: packet filtering checks your ticket's basic details, stateful inspection remembers you already passed and lets your return match through, and the application-layer check actually opens your bag to see what's inside.
living diagram01 / 05
packetsInternetuntrustedPacket filterL3/L4 · IP·port·protocolStateful inspectconnection tableApp-layer / WAFL7 · payload rulesInternal networktrusted segmentHost firewallper-machine
01

Traffic hits the boundary

Every packet trying to cross from an untrusted network (the internet) into a trusted one arrives first at the firewall. The firewall's whole job is to sit on that boundary and decide, for each packet or connection, whether it may pass. The default posture in any serious setup is deny-everything, then explicitly allow only what's needed.

02

Packet filtering (L3/L4)

The most basic firewall examines each packet's headers in isolation — source and destination IP, port and protocol — and matches them against a rule list. A rule like 'allow TCP to port 443, deny everything else' is evaluated top to bottom until one matches. It's extremely fast and cheap, but because it judges packets one at a time it has no memory of connections.

03

Stateful inspection

A stateful firewall keeps a connection table recording every active session it has approved. When you open an outbound connection, its return traffic is recognized as belonging to that established session and allowed automatically, without a separate rule. This both tightens security — unsolicited inbound packets that match no known connection are dropped — and simplifies the rule set.

04

Application-layer / WAF

An application-layer firewall reads the actual payload at L7, understanding HTTP requests, not just ports. A Web Application Firewall (WAF) sits in front of web apps and inspects requests for attack signatures — SQL injection strings, cross-site scripting, path traversal — blocking malicious content that a port-based firewall would happily wave through. It's deeper and smarter, but slower and protocol-specific.

05

Network vs host firewalls

A network firewall guards an entire segment at the perimeter, filtering traffic for everything behind it. A host firewall runs on an individual machine and protects just that host, even from threats already inside the network. Real defense-in-depth uses both: the perimeter firewall blocks the bulk, and per-host firewalls contain anything that slips past.

the full picture
01

What a firewall is and why it exists

A firewall is a security device — hardware, software, or a cloud service — that sits at a boundary between networks and controls what traffic is allowed to cross it. The name is a metaphor borrowed from building construction, where a firewall is a barrier that stops a fire from spreading from one section to the next. A network firewall does the same thing for traffic: it separates a trusted zone (your internal network, your servers) from an untrusted one (the public internet) and enforces a policy about what may pass between them.

The reason firewalls exist is that a network with no boundary control is completely exposed — any machine on the internet can attempt to connect to any port on any of your systems. That is an enormous attack surface. A firewall shrinks it to a deliberate minimum by enforcing a simple, powerful default: deny everything, then explicitly allow only the specific traffic your services actually need. Every packet that does not match an allow rule is dropped. This "default-deny" stance is the single most important idea in firewalling, because it means a service you forgot about, or a port you never meant to expose, is closed by default rather than open by accident.

02

Rules: the language of allow and deny

A firewall's behavior is defined by an ordered list of rules. Each rule describes a kind of traffic and an action to take when traffic matches it. The classic fields a rule matches on are:

  • Source and destination IP address — where the traffic is coming from and going to.
  • Port — which service is being addressed (443 for HTTPS, 22 for SSH, and so on).
  • Protocol — TCP, UDP, ICMP, etc.
  • Direction — inbound to the network or outbound from it.

The action is almost always allow (let it through), deny/drop (silently discard it), or reject (discard and tell the sender). Rules are evaluated top to bottom, and the first match wins, so ordering matters: a broad rule placed above a specific one can accidentally shadow it. A typical policy might read "allow inbound TCP to port 443 from anywhere, allow inbound TCP to port 22 only from the office IP range, deny all other inbound." The final catch-all deny is what makes the whole thing default-deny. Writing good rules is really an exercise in expressing the smallest possible set of things you want to permit.

03

Three generations of inspection

Firewalls are usually classified by how deeply they look at traffic, which corresponds to how much of the network stack they understand.

Packet filtering is the original and simplest. It works at the network and transport layers (L3/L4), inspecting each packet's headers — IP addresses, ports, protocol flags — in complete isolation and matching them against the rule list. It is blazingly fast and cheap because it holds no context, but that is also its weakness: judging every packet on its own, it cannot tell whether an incoming packet is an unsolicited intrusion or a legitimate reply to a request one of your machines just made.

Stateful inspection fixed that by giving the firewall a memory. It maintains a connection table (a state table) tracking every active session — who initiated it, to where, and its current state. When your server opens an outbound connection, the firewall records it, and the return traffic is automatically recognized as part of that established connection and allowed, with no separate inbound rule required. Packets that belong to no known connection are dropped. This is both more secure and simpler to configure, and it is why virtually every modern firewall is stateful by default.

Application-layer firewalls go deeper still, reading the actual content at L7. Instead of only seeing "TCP to port 80," they parse the HTTP request itself. The most common example is a Web Application Firewall (WAF), which sits in front of web applications and scans requests for attack patterns — SQL injection payloads, cross-site scripting, path traversal, known exploit signatures — and blocks them before they reach the app. This is protection a port-based firewall simply cannot provide, because the malicious request arrives on a legitimately open port (443) and looks fine at L3/L4. The cost is performance and specificity: parsing payloads is heavier work, and a WAF must understand the specific application protocol it guards.

04

Where firewalls live: network vs host

Firewalls also differ by where they sit, and the two placements complement rather than replace each other.

A network firewall guards an entire network segment from a single choke point at the perimeter. All traffic entering or leaving the protected zone passes through it, so one device (or cluster) enforces policy for everything behind it. This is efficient and centralizes control, and it is what most people picture — the box between the internet and the corporate LAN, or the security group in front of a cloud VPC.

A host firewall runs as software on an individual machine (Windows Firewall, Linux iptables/nftables, macOS's built-in firewall) and protects only that one host. Its value is that it defends the machine even against threats already inside the network — a compromised laptop on the same LAN, or lateral movement after an attacker breaches the perimeter. Because it runs on the endpoint, it can also apply per-application rules the network can't see.

Serious environments run both, an approach called defense in depth. The perimeter firewall blocks the vast bulk of unwanted traffic cheaply, and per-host firewalls provide a second, inner layer so that a single breach of the perimeter does not leave everything behind it wide open.

05

Limits, failure modes, and practical guidance

Firewalls are essential but not magic, and understanding their limits is part of using them well. A firewall only inspects traffic that passes through it — it does nothing about a threat that originates inside the trusted zone or arrives by a path that bypasses it (an infected USB drive, a malicious download a user willingly ran). It also cannot see inside encrypted traffic unless it terminates the encryption, which is why WAFs and next-generation firewalls often decrypt TLS to inspect and then re-encrypt, a powerful but sensitive capability.

The most common real-world failures are misconfiguration, not technology: an overly broad allow rule, rules left over from a decommissioned service, or a permit rule accidentally ordered above the deny that was supposed to stop it. Because first-match-wins, a single sloppy rule can quietly undo the whole policy. The discipline that prevents this is to keep the rule set as small and specific as possible, default to deny, log denied traffic so you can see what is being blocked and what is probing you, and review rules regularly to prune the ones no longer needed. In modern cloud infrastructure these ideas appear as security groups and network ACLs, which are firewalls by another name, plus managed WAFs at the CDN edge. The principles are identical: define a boundary, default-deny, allow the minimum, and layer inspection so that the deeper, smarter checks back up the fast, shallow ones.

what to remember
01

A firewall filters traffic at a boundary, allowing or denying it based on configured rules.

02

Rules match on IP address, port, protocol and direction, with an action of allow or deny.

03

Packet filtering (L3/L4) judges each packet in isolation — fast, but blind to connection context.

04

Stateful inspection tracks connections in a table, so replies to allowed outbound traffic are permitted automatically.

05

Application-layer firewalls and WAFs read L7 payloads to block attacks like SQL injection and XSS.

06

Network firewalls guard a whole segment at the perimeter; host firewalls protect a single machine — use both.

check yourself

Quick quiz

Q1

What can a stateful firewall do that a pure packet filter cannot?

Q2

Which firewall type is designed to block SQL injection and XSS in web requests?

follow the thread