The primary function of a firewall is to control the flow of network traffic between networks with different security policies, allowing legitimate traffic through and blocking everything else. It sits at the boundary between a trusted network and an untrusted one, such as the internet, and enforces a set of rules about which connections, addresses, ports and applications are permitted.
Key takeaways
- A firewall's core job is traffic control: it allows permitted connections and blocks the rest at a network boundary.
- Firewalls come as hardware, software, packet filters, stateful inspectors and next-generation firewalls that inspect applications.
- A firewall cannot stop malware you install yourself, phishing, or attacks from inside the network — it is one layer, not total protection.
Every device on your network is constantly talking to the internet, and the internet is constantly trying to talk back. A firewall is the checkpoint in the middle: it decides which of those conversations are allowed and which get turned away.
What is the primary function of a firewall?
The primary function of a firewall is to control the flow of network traffic between networks that have different security policies. It allows traffic that matches its rules and blocks traffic that does not.
NIST defines firewalls as "devices or programs that control the flow of network traffic between networks and between hosts that employ different security policies". RFC 4949, the Internet Security Glossary, describes a firewall as an internetwork gateway that restricts traffic to and from the protected network, shielding its systems from threats on the outside network.
In practice, that means the firewall sits at the boundary between your trusted network and an untrusted one, usually the internet, and applies policy rules to everything crossing that boundary. It protects against outside attackers, blocks unauthorized access attempts, and can also stop malicious software from reaching out to the internet. CISA's guide to firewalls for home and small office use explains the same job in plain terms.
That control job is the firewall's one core purpose. Everything else a firewall does, from logging to intrusion prevention, exists to support that decision: allow or block.
How does a firewall work?
A firewall inspects each packet or connection and compares it against its rule set. If the traffic matches an allow rule, it passes; if it matches a block rule, or no rule at all, it is dropped.
Each rule looks at facts about the traffic: the source and destination addresses, the port number, the protocol, and, for more advanced firewalls, the application and the content. A rule might say "allow web traffic to the company website on port 443" and another might say "block all traffic from this known malicious address".
Stateful firewalls go further by remembering connections. When your computer starts a web request, the firewall records that session in a state table, so the reply is recognized as part of a legitimate conversation and allowed back in. Unsolicited traffic that does not belong to any session your network started is blocked.
Modern firewalls can also inspect the contents of traffic, not just its envelope. Deep packet inspection looks inside packets for signs of attacks, and next-generation firewalls can decrypt TLS traffic to inspect it, then re-encrypt it. That matters because most web traffic is now encrypted, and a firewall that cannot see inside it is partly blind.
What are the main types of firewalls?
Firewalls differ in how deeply they inspect traffic. The older types look at addresses and ports; the newer ones understand applications and can spot attacks hidden inside legitimate-looking traffic.
| Type | What it inspects | Strengths | Weaknesses |
|---|---|---|---|
| Packet filtering | Addresses, ports, protocol | Fast, simple, cheap | No memory of connections; cannot see content |
| Stateful inspection | Packets plus connection state | Blocks unsolicited replies; standard today | Limited view of application content |
| Application layer | Application protocols | Deep inspection of specific apps | Slower; tuned per application |
| Next-generation (NGFW) | Apps, users, content, threats | App awareness, IPS, TLS inspection | More complex and costly |
| Web application (WAF) | HTTP traffic to web apps | Blocks SQL injection, cross-site scripting | Only protects web traffic |
| Unified threat management | Firewall plus antivirus, IPS and more | One box for small teams | Needs enough CPU for every job at once |
NIST's firewall guidance, SP 800-41, describes packet filtering, stateful inspection, application firewalls, and unified threat management as the main categories. The next-generation firewall builds on these with application awareness, deep packet inspection, TLS decryption with payload inspection, and intrusion prevention.
A web application firewall, or WAF, is a specialist: it sits in front of web servers and inspects HTTP requests for attacks such as SQL injection. NIST notes it is often considered quite different from a traditional firewall, and it protects web traffic only.
Hardware vs software firewalls: what's the difference?
A hardware firewall is a physical device placed between your network and the internet. It protects every computer behind it at once and adds a line of defense outside the machines themselves, which is why it suits offices and homes with several devices.
A software firewall runs on one computer and controls that machine's own traffic, including which applications may use the network. Most operating systems include one: Windows Defender Firewall and macOS's built-in firewall are already on your computer, and Linux systems often use nftables or firewalld.
CISA's advice is simple: the decision to use a firewall matters more than which type you choose, and you should use both where you can. A hardware firewall guards the perimeter, while a software firewall protects a laptop that leaves the office and connects to hotel Wi-Fi. The software firewall also needs managing on every machine, which is its main drawback in a larger network.
Cloud firewalls are a third option: rules enforced by your cloud provider around virtual machines and services, such as AWS security groups. They work like a network firewall but are defined in software and travel with the workload.
What can a firewall not do?
A firewall is powerful at the boundary, and limited everywhere else. Knowing its limits is as important as knowing its function, because overconfidence is how breaches happen.
- It cannot stop malware you install. If you download and run a malicious file, the firewall will not object, because you authorized the action. CISA warns that firewalls primarily protect against malicious traffic, not malicious programs.
- It cannot stop phishing. A fake login page delivered by email looks like ordinary web traffic. The firewall sees an allowed connection to a website; it cannot tell you are being tricked.
- It cannot see inside the network. Traffic between two computers on the same network often never passes through the perimeter firewall, so an infected laptop can attack its neighbors unchecked.
- It cannot fix bad rules. A misconfigured firewall can block legitimate work or quietly allow dangerous traffic. CISA notes that default configurations are often less restrictive than they could be.
- It cannot inspect what it cannot read. Encrypted traffic is opaque unless the firewall decrypts it, which needs extra setup and has privacy trade-offs.
- It cannot protect an unpatched device. If a firewall itself has a known vulnerability, attackers target it directly, since it faces the internet and often carries VPN access.
The answer to these limits is defense in depth: combine the firewall with antivirus, patching, phishing-resistant MFA, and backups. For a home network, our guide to how to secure your Wi-Fi covers the firewall settings on a typical router alongside the other basics.
How do you set up a firewall correctly?
Correct setup is mostly discipline: a tight default policy, a short list of deliberate exceptions, and regular review. Follow these steps for a home or small-office firewall.
- Turn it on. Enable the firewall on your router and on every computer. Check that the built-in operating system firewall is active, even behind a hardware firewall.
- Use default-deny. Block all incoming traffic by default, then allow only what you need. Outbound traffic can start permissive, then be tightened for servers and sensitive machines.
- Allow by exception, with reasons. Every open port should have a named purpose and owner. Close ports for services you no longer run, such as an old remote desktop rule.
- Keep it updated. Apply firmware and software updates promptly. Firewall devices are a prime target, and vendors regularly patch flaws in them.
- Turn on logging and review it. Logs show blocked attempts and rule hits. A sudden spike in blocked traffic, or a rule that never fires, tells you something changed.
- Review rules on a schedule. Rules accumulate like clutter. A quarterly review that removes stale rules is one of the highest-value firewall habits.
- Test from outside. Scan your public address from outside your network to confirm that only the intended ports respond.
For businesses, the same steps apply at larger scale, with change control: every rule change is requested, approved, and recorded, so nobody can open a port quietly and forget it.
Firewall vs antivirus: what's the difference?
A firewall controls network traffic, while antivirus inspects files and programs on a device. The firewall decides which connections may cross a boundary; antivirus decides whether a file or program is malicious and stops it from running.
They overlap in one place: some firewalls and unified threat management devices include malware scanning of traffic. Even then, the on-device antivirus remains the last line, because it can see a file after it is downloaded and watch what it does.
You need both. A firewall without antivirus leaves you exposed to anything that arrives through an allowed channel, such as an email attachment. Antivirus without a firewall leaves your computer's ports open to anyone on the network who probes them. Together with prompt patching, they form the baseline of endpoint protection.
The bottom line
The primary function of a firewall is traffic control: allow what your rules permit, block everything else, and do it at the boundary between networks you trust and networks you do not. That single job is the foundation of network security.
Turn on the firewalls you already have, set them to deny by default, and review the rules regularly. Then add the layers a firewall cannot provide: antivirus, updates, and phishing-resistant MFA. The small business cybersecurity checklist walks through those layers step by step.
You can check your own connection's public address and exposure with our free what-is-my-IP tool.
Frequently asked questions
What is the primary function of a firewall in simple terms?
A firewall is a gatekeeper for network traffic. It checks every connection trying to enter or leave your network against a set of rules, lets the allowed traffic through, and blocks the rest.
Is a firewall hardware or software?
It can be either. A hardware firewall is a physical device between your network and the internet, often built into a router. A software firewall runs on a computer and controls that machine's own traffic. Most networks use both.
Does a firewall protect against viruses?
Only partly. A firewall blocks malicious network traffic and can stop some malware from reaching you or calling home. It cannot remove malware already on your computer or stop you from installing a malicious file yourself.
Do I need a firewall if I have antivirus?
Yes. They do different jobs: a firewall controls network connections, while antivirus inspects files and programs on a device. CISA recommends using both together with safe computing habits.
Should a firewall block all incoming traffic?
By default, yes. The safe approach is to block everything and then allow only the specific traffic you need, such as web browsing replies. This is called a default-deny policy.
What is a next-generation firewall?
A next-generation firewall adds application awareness, deep packet inspection, TLS inspection and intrusion prevention to the basic allow-or-block job. It can tell which application is using a connection, not just which port.
Can a firewall block a website?
Yes. A firewall can block traffic to specific addresses, domains or ports. Application-aware firewalls can also block specific web applications or categories of sites.
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 CISA's firewall guidance for home and small office use, NIST SP 800-41, and the firewall definition in IETF RFC 4949.
How we write and fact-check →