How Does a Firewall Work?
What does a firewall actually do?
Every bit of data that reaches your computer arrives as a packet, a small chunk with a header that says where it came from, where it's going, and which port it's headed for. A firewall inspects those headers and compares them to its rules. Allow, deny, or drop. That's the whole loop, repeated millions of times a day.
The short answer is that a firewall is a filter, not a wall. It doesn't make your computer invisible. It decides which conversations are allowed to happen.
What is a packet filter vs. a stateful firewall?
Older packet filters judged each packet on its own, like a bouncer who checks IDs but never remembers faces. A stateful firewall keeps track of connections: if your browser asked for a page, the reply is expected and gets through. Anything arriving uninvited gets stopped. Most modern firewalls are stateful.
What is the difference between a hardware and software firewall?
| Type | Where it lives | What it typically guards |
|---|---|---|
| Hardware | In your router or a dedicated appliance | Everything on the network at once |
| Software | On the device itself | That one machine |
You usually have both without thinking about it. Your router has a firewall on by default, and Windows and macOS each ship with one.
What can a firewall not stop?
Plenty. A firewall checks addresses and ports, not intentions. If you click a bad link and your browser starts an outbound connection, the firewall sees a legitimate request and lets it through. Phishing, malicious downloads, and anything you approve yourself can walk right past it. That's why firewalls get paired with antivirus software and plain old caution.
Why do firewalls block some ports and not others?
Ports are numbered doorways for specific services. Port 80 is plain web traffic, 443 is encrypted web traffic, 22 is often remote login. Closing a port you don't use removes a doorway an attacker could try. That's the logic behind the default deny rule: block everything, then open only what you need.
A fun bit of history: the term comes from firefighting, where a fire wall is a barrier meant to stop flames spreading from one building to the next. The computing version borrowed the idea in the late 1980s, when the first network firewalls were built at places like Bell Labs and Digital Equipment Corporation.