A firewall is a device or program that controls the flow of network traffic between networks or hosts with different security postures, allowing or blocking traffic according to a policy. It sits at a network boundary, checks each packet or connection against its rules, and permits, drops or rejects traffic that does not match. It is a first layer of defense, not complete protection on its own.
Key takeaways
- A firewall enforces a policy at a network boundary: it permits, drops or rejects traffic by rule.
- Stateful and next-generation firewalls inspect connection state and applications, not just ports.
- A firewall cannot stop phishing, stolen passwords or malware you install yourself.
Every device on the internet is constantly probed by strangers. A firewall is the gatekeeper that decides which of those connection attempts reach your network, and which are turned away.
What is a firewall?
A firewall is a device or program that controls the flow of network traffic between networks or hosts that employ differing security postures. That is the definition used by NIST in SP 800-41 Rev. 1, the US government's firewall guidance.
In plain terms, a firewall sits at a boundary between a trusted network and a less trusted one, such as your home network and the internet, and enforces a policy about what may cross. NIST's SP 800-41 Rev. 1 is the full guidance behind that definition.
The name comes from fire walls in buildings and vehicles: a barrier that limits how far damage can spread. A network firewall does the same by segmenting networks, so a problem in one part does not automatically reach the rest.
What is a firewall in a computer network?
In a computer network, a firewall is the enforcement point where traffic between zones of different trust is checked. Those zones can be your laptop and the internet, an office network and a guest network, or a public-facing server area and an internal database.
A firewall can take several forms. It may be built into a home router, installed as software on Windows, macOS or Linux, deployed as a dedicated network appliance, or delivered as a cloud service. The form changes; the job does not.
Most networks use more than one firewall. A router firewall guards the internet edge, a host firewall guards each computer, and a cloud firewall guards web applications. Each one enforces policy at its own boundary.
What is the firewall definition used by NIST?
NIST's glossary gives several overlapping definitions, all from its published guidance. The most useful is from SP 800-41 Rev. 1: a firewall is a device or program that controls the flow of network traffic between networks or hosts that employ differing security postures.
An older NIST definition calls it a gateway that limits access between networks in accordance with local security policy. Another, from SP 800-152, describes it as a part of a computer system or network designed to block unauthorized access while permitting outward communication.
The common thread is control by policy. A firewall does not decide what is safe in general; it enforces the decisions its owner has written into rules. That is why a firewall is only as good as its policy, its placement and its maintenance.
What does a firewall do?
A firewall controls communications across a boundary. It blocks unsolicited inbound connections, closes ports that no legitimate service uses, stops a specific application from reaching the network, and logs suspicious activity for review.
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 in one sentence.
In practice, a firewall also segments a network. A guest network, a smart-home network and a work network can each have different rules, so a compromised camera cannot reach a laptop. Outbound filtering is often the more valuable half: it limits what a compromised internal device can reach.
How does a firewall work?
A firewall receives a packet or connection, identifies its relevant characteristics, compares them with its policy, and applies the action for the matching rule. That sequence is the same for a home router and an enterprise appliance.
- Receive. A packet or connection reaches a firewall interface, zone or cloud policy boundary.
- Identify. The firewall reads the source and destination addresses, ports, protocol and connection state. More advanced firewalls also identify the application, user or content.
- Evaluate. The firewall compares the traffic with its rules, usually in order, from the most specific match to the least specific.
- Decide. If a rule matches, its action applies: allow, deny, drop or inspect. If no rule matches, the default policy applies, which should be deny by default.
- Log. The firewall records accepted connections, blocked attempts, administrative changes and errors for review.
Stateful firewalls add one more step: they track the state of active connections, so return traffic for a connection you started is allowed automatically, while unsolicited traffic is not. That is how your browser can receive a reply without the firewall opening a permanent hole.
What are the main types of firewalls?
Firewalls have evolved in layers since the 1980s, and most modern products combine several types. The table below compares the main kinds.
| Type | What it checks | Best for | Limitation |
|---|---|---|---|
| Packet-filtering | Addresses, ports, protocol | Simple, fast filtering | No connection or application awareness |
| Stateful inspection | Connection state plus headers | Most home and office networks | Cannot see inside encrypted or application content |
| Proxy firewall | Application requests, acting on your behalf | Controlled web access | Slower; needs configuration per protocol |
| Next-generation firewall (NGFW) | Application, user, content and threats | Businesses needing deep inspection | More complex and more expensive |
| Web application firewall (WAF) | HTTP requests to a web app | Protecting websites and APIs | Only covers web traffic |
| Host firewall | Traffic on one computer | Every laptop and server | Only protects that one device |
| Cloud firewall | Traffic to cloud services | Cloud and remote teams | Depends on the provider's policy model |
Packet filtering is the oldest and simplest type: it reads packet headers and allows or blocks by address, port and protocol. Stateful inspection improves on it by tracking connections. Application firewalls and next-generation firewalls go further, reading protocol content and applying application and threat rules.
NIST notes that threats have moved from lower network layers to the application layer, which has reduced the general effectiveness of simple firewalls against threats carried by network communications. That is why modern firewalls add application inspection, intrusion prevention and threat intelligence.
What is the difference between a hardware and a software firewall?
A hardware firewall is a separate device, usually a router or a dedicated appliance, that protects a whole network. A software firewall is a program running on one computer that protects that computer.
Hardware firewalls guard the network edge and can segment traffic between zones. They are always on, they protect every device behind them, and they do not depend on any one computer being switched on. Software firewalls guard the host: they can control traffic per application, which a network firewall cannot always see.
Most people need both. Your router's hardware firewall blocks unsolicited inbound traffic, and your computer's software firewall controls which applications on that computer may send or receive data. If you want per-device control for a whole home, see our guide to the best firewall for a home network.
How is a firewall different from antivirus and a VPN?
These three tools are often confused because they all relate to security, but they do different jobs at different layers.
- Firewall: controls network traffic at a boundary. It decides what may cross, not whether a file is malicious.
- Antivirus: scans files and programs on a device for malware. It catches what a firewall lets through because you asked for it.
- VPN: encrypts traffic between two points. It hides the contents from observers on the path, but it does not decide which traffic is allowed.
A VPN can actually bypass a firewall if it is not configured carefully, because encrypted traffic is harder to inspect. That is why organizations route VPN traffic through the firewall and apply the same policy to it as to any other traffic.
What can a firewall not do?
A firewall cannot stop attacks that do not cross it, or that cross it with permission. That is its main limitation, and it is worth stating plainly.
- Phishing: if you click a link and enter a password, the firewall sees an ordinary web request.
- Stolen credentials: an attacker who logs in with a valid password looks like a legitimate user.
- Malware you install: if you download and run a malicious program, the firewall cannot undo that choice.
- Insider misuse: a firewall cannot stop someone who already has authorized access from misusing it.
- Encrypted threats: a basic firewall cannot inspect encrypted traffic without decryption, which needs its own controls.
That is why a firewall is a first layer, not a complete defense. Patching, strong authentication, backups and user awareness cover the attacks a firewall cannot see. Our small business cybersecurity checklist puts those layers together in one plan.
How do you set up a firewall?
Setting up a firewall means writing a policy, applying it, and then checking that it works. The steps below work for a home router and, at a larger scale, for a business appliance.
- Turn it on. Enable the firewall in your router and on every computer. Check that it is actually running, not just installed.
- Start with deny by default. Block everything, then allow only what you need. NIST's control SC-7(5) calls this deny by default, allow by exception.
- Allow only needed services. Open only the ports and applications you actually use, and close the rest.
- Segment the network. Put guests and smart-home devices on separate networks from work computers where your router supports it.
- Turn on logging and alerts. Review blocked attempts occasionally; a sudden change can be an early warning.
- Update firmware and rules. Patch the firewall itself, and review the rules when you add a device or service.
- Test it. Check that a blocked port is actually blocked, and that a needed service still works.
For home Wi-Fi specifically, our guide on how to secure your Wi-Fi walks through router settings step by step.
What are common firewall mistakes?
Most firewall failures are configuration failures. The firewall is running, but the policy is wrong, out of date or never reviewed.
- Allow-all rules left over from setup. Temporary rules become permanent. Review them regularly and remove what is no longer needed.
- Opening ports for one device and forgetting them. Port forwarding for a game or camera should be temporary and specific, not permanent and broad.
- Disabling the firewall to fix a problem. If an application does not work, find the rule it needs instead of turning the firewall off.
- Never checking logs. Logs are the only way to know whether the firewall is blocking real attacks or blocking legitimate traffic.
- Forgetting the host firewall. A network firewall does not protect a laptop on public Wi-Fi. The host firewall does.
The bottom line
A firewall is a device or program that controls network traffic between networks with different levels of trust, enforcing a policy you define. It blocks unsolicited connections, closes unused ports, segments networks and logs what it sees.
Turn on the firewall in your router and on every computer, start with deny by default, and review the rules when your network changes. You can check what your connection looks like from the outside with our free what-is-my-IP tool.
Frequently asked questions
What is a firewall in simple terms?
A firewall is a gatekeeper for a network. It checks traffic crossing a boundary, such as between your home network and the internet, and lets through only what its rules allow. Everything else is blocked or dropped.
What is a firewall in a computer network?
In a computer network, a firewall is a device or program that controls traffic between networks or hosts with different levels of trust. It can be built into a router, installed on a computer, deployed as an appliance, or delivered as a cloud service.
What does a firewall do?
A firewall permits, rejects or drops network traffic according to a policy. It can block unsolicited inbound connections, close unused ports, stop a specific application from reaching the network, and log suspicious activity for review.
How does a firewall work?
A firewall receives a packet or connection, reads its source, destination, protocol, ports and connection state, compares those details with its rules in order, and applies the matching action: allow, deny, drop or log. More advanced firewalls also inspect the application and content.
Do I need a firewall at home?
Yes, and you almost certainly already have one. Your router includes a basic firewall, and Windows and macOS include a software firewall. Leave both on, keep them updated, and add a dedicated firewall only if you have many smart devices or want per-device control.
Is a firewall the same as antivirus?
No. A firewall controls network traffic at a boundary, while antivirus scans files and programs on a device for malware. They do different jobs and you need both.
Can a firewall block all attacks?
No. A firewall blocks unwanted network traffic, but it cannot stop a phishing email, a stolen password, or malware you install yourself. It is one layer in a wider set of defenses.
What is the difference between a firewall and a VPN?
A firewall decides which traffic may cross a network boundary. A VPN encrypts traffic between two points and makes a remote connection look local. Many organizations use both: a VPN for remote access, and a firewall to control what that access can reach.
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 and the NIST CSRC firewall glossary, plus CISA guidance for home and small office use.
How we write and fact-check →