The purpose of a firewall is to control network traffic between networks or hosts with different levels of trust, allowing only the traffic your security policy permits and blocking the rest. It sits at the boundary between a trusted network, such as your home or office, and an untrusted one, such as the internet, and checks each connection against a set of rules based on addresses, ports, protocols, applications and connection state.
Key takeaways
- A firewall enforces a policy at a network boundary: it allows approved traffic and blocks or drops the rest.
- Stateful and next-generation firewalls understand connections and applications, not just individual packets.
- A firewall is one layer only: it cannot stop phishing, stolen passwords, malware you install, or attacks from inside.
Every device on the internet is constantly probed. Scanners look for open ports, forgotten services and weak logins, all day, every day. A firewall is the control that decides which of those connection attempts ever reach your devices.
What is the purpose of a firewall?
The purpose of a firewall is to control the flow of network traffic between networks or hosts with different security policies, so only approved traffic gets through. NIST describes a firewall as a gateway that limits access between networks in accordance with local security policy.
In plain terms, a firewall is a policy enforcement point. It does not decide what is good or bad in the abstract; it applies the rules you set. If a connection matches an allow rule, it passes. If it matches a block rule, or matches no allow rule, it is dropped or rejected.
CISA puts it plainly for home and small-office users: firewalls can be configured to block data from certain network addresses, applications or ports while still letting necessary, legitimate traffic through. That is the whole job, and it is an important one. HP's explainer makes the same point: a firewall acts as a gatekeeper between trusted and untrusted networks.
How does a firewall work?
A firewall works by sitting on the path traffic must cross, examining each packet or connection, comparing it with its rules, and then allowing, blocking, dropping or logging it. The basic process is the same for a home router and a large corporate firewall.
A firewall checks attributes such as the source and destination IP address, the port number, the protocol, the application, the user and the connection state. A simple rule might read: allow web traffic to port 443, block everything else from the internet.
The safest default is deny by default: block everything, then allow only what you need. That way a new service you install is closed until you deliberately open it. NIST SP 800-41 Rev. 1, the US government's firewall guidance, recommends this approach and a written firewall policy, as summarized in this overview of NIST firewall guidance.
What are the main types of firewall?
The main types are packet-filtering, stateful inspection, proxy or application-gateway, next-generation and web application firewalls. Modern products often combine several approaches, so the labels describe capabilities, not separate boxes you must buy one of.
| Type | What it checks | Strength | Weakness |
|---|---|---|---|
| Packet-filtering | Packet headers: address, port, protocol | Fast and simple | No memory of connections |
| Stateful inspection | Headers plus connection state | Recognizes replies to your requests | Cannot see inside encrypted content |
| Proxy / application gateway | Full application traffic, as an intermediary | Deep inspection, hides internal hosts | Slower, needs per-protocol support |
| Next-generation (NGFW) | Application, user and threat data | Blocks apps and known threats | More complex and costly |
| Web application (WAF) | HTTP traffic to a website | Blocks web attacks such as injection | Only protects web apps |
Packet-filtering firewalls
A packet-filtering firewall examines the header of each packet and allows or blocks it on address, port and protocol alone. It is fast, but it treats every packet as independent, so it cannot tell a reply from a new attack.
Stateful inspection firewalls
A stateful firewall tracks active connections, so it knows that an incoming packet is a reply to a request your device just made. NIST describes stateful inspection as maintaining information about connections and using it when filtering traffic.
Next-generation firewalls
A next-generation firewall adds application awareness, intrusion prevention and threat intelligence to stateful inspection. It can block a specific application, such as a file-sharing tool, even when that application uses a normal web port.
Web application firewalls
A web application firewall protects a website or web application by inspecting HTTP traffic for common attacks. OWASP notes that WAFs are designed to protect web applications, and they are not a replacement for a network firewall.
Hardware vs software firewalls: which do you need?
You need both, because they protect different places. A hardware or network firewall sits at the edge of your network and protects everything behind it. A software or host firewall sits on one device and protects that device wherever it goes.
Your home router is a hardware firewall. It blocks unsolicited inbound connections from the internet, so a scanner cannot reach your laptop directly. Windows Defender Firewall and macOS Firewall are host firewalls: they control which applications on that computer can send or receive traffic.
The host firewall matters most on a laptop that leaves the house. On public Wi-Fi, there is no router firewall between you and the network, so the host firewall is the only boundary. Keep both turned on. For the Wi-Fi side of this, see our guide on how to secure your Wi-Fi.
What does a firewall actually protect you from?
A firewall protects you from unsolicited inbound connections, scans and probes, and from applications or devices talking to places they should not. It also limits lateral movement: if one device is compromised, a segmented firewall can stop the attacker reaching the next one.
- Port scans and probes: blocked before they reach a service.
- Exposed services: a forgotten file share or camera is not reachable from the internet.
- Unwanted outbound traffic: an application is stopped from reaching a known bad address.
- Lateral movement: internal segments, such as accounting or IoT devices, are isolated from each other.
Firewalls also log what they block, which gives you evidence during an investigation. A sudden rise in blocked attempts from one address, or a device repeatedly trying to reach an unusual destination, is a useful early warning.
What can a firewall not do?
A firewall cannot stop phishing, stolen passwords, malware you install, or an attacker who already has valid credentials. It controls network traffic; it does not judge whether a login, an email or a download is trustworthy.
It also cannot inspect traffic it cannot see. Encrypted traffic is opaque unless the firewall decrypts it, which most home firewalls do not do. And it cannot protect a device that is already compromised and allowed to talk out, unless an egress rule blocks that destination.
That is why a firewall is one layer in defense in depth, alongside patching, phishing-resistant MFA, endpoint protection, safe browsing and backups. NIST's firewall guidance makes the same point: firewalls are essential, but they are not a complete security solution on their own.
How do you set up a firewall safely?
Set up a firewall by keeping the defaults on, closing what you do not need, and reviewing the rules when something changes. For most homes, the defaults are already close to right.
- Turn it on: enable the router firewall and the host firewall on every computer and phone.
- Change the admin password: use a strong unique password for the router, not the default.
- Update firmware: router firmware fixes firewall bugs, so install updates promptly.
- Close what you do not use: remove port forwards you no longer need, and disable UPnP if nothing requires it.
- Segment where you can: put guest devices and smart-home gadgets on a separate network from your main computers.
For a business, write the policy down: who can approve a rule, what each rule is for, and when it expires. Review the rules at least once a year, because rules added for a temporary project often stay open for years. Our small business cybersecurity checklist includes firewall and network checks alongside the rest.
The bottom line
A firewall exists to enforce a simple idea: only the traffic you have approved should cross the boundary between your network and the rest of the world. It does that job well, and it does it quietly, every second.
Keep it on, keep it updated, keep the rules minimal, and pair it with MFA, patching and backups. You can check whether your own site is exposed over the web with our free security headers checker.
Frequently asked questions
What is the purpose of a firewall in simple terms?
A firewall is a gatekeeper for network traffic. It checks connections coming in and going out, lets through the ones your rules allow, and blocks the ones they do not, so unwanted traffic never reaches your devices.
Do I need a firewall at home?
Yes, and you almost certainly already have one. Your router has a firewall, and Windows and macOS include a host firewall. Keep both turned on, keep firmware updated, and do not open ports you do not need.
What is the difference between a hardware and a software firewall?
A hardware or network firewall protects a whole network or segment at its boundary. A software or host firewall protects one device. Most homes and offices need both, because they cover different places.
Can a firewall stop viruses and malware?
Not on its own. A firewall blocks unwanted network connections, but it cannot stop malware you download, open in an attachment, or install yourself. You still need endpoint protection, updates and safe habits.
What is a next-generation firewall?
A next-generation firewall combines packet filtering and stateful inspection with application awareness, intrusion prevention and often threat intelligence. It can block a specific application or a known malicious site, not just a port.
Is a firewall the same as antivirus?
No. A firewall controls network traffic, while antivirus and endpoint protection look for malicious files and behavior on a device. They do different jobs and work best together.
Should I turn off my firewall?
No, unless you are replacing it with another firewall and understand the risk. Turning it off leaves every port and service on that device or network exposed to direct connection attempts.
Does a firewall slow down the internet?
A well-configured firewall adds very little delay for home and small-office use. A badly configured or overloaded firewall can slow traffic, so keep rules simple and firmware current.
Sources
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.
Checked against NIST SP 800-41 Rev. 1, CISA firewall guidance for home and small offices, and OWASP guidance on web application firewalls.
How we write and fact-check →