A firewall is a network security system that monitors and controls incoming and outgoing traffic based on a rule set. It sits between a trusted inside network and an untrusted outside network like the internet, checks each data packet that tries to cross, and decides to allow or block it. That helps stop unauthorized access, block potential threats and keep sensitive data safe. Whether hardware, software or cloud-based, a firewall is a first line of defense for public and private networks alike. Below, you will learn how a firewall works, what types of firewalls exist, and how to choose the right one for your cybersecurity setup.
What a Firewall Does and Why It Matters
A firewall is a network device or program that filters traffic between your network and the outside world. It acts as a guard at the gate. Every time a data packet tries to enter or leave your network, the firewall checks it against a set of rules. If the packet matches a safe rule, it passes through. If it does not, the device blocks it. This filter model is the core of every firewall type, from basic packet filtering firewalls to advanced next generation firewall (NGFW) platforms.
Firewalls matter because networks face constant threats. Hackers probe for open ports. Malware tries to phone home. Insiders may try to send data out. Without a firewall, this traffic flows freely. A firewall gives admins control over what gets in and what gets out. It enforces network security rules that match the firm’s risk profile. A firewall can block all incoming traffic on port 23 (Telnet) while allowing port 443 (HTTPS). This fine-grained control over incoming and outgoing traffic is what makes a firewall essential for threat protection.
Logging, NAT, and VPN
Beyond blocking bad traffic, a firewall logs the actions it takes. These logs feed into SIEM tools and help security teams spot patterns, like repeated port scans from a single IP. Modern firewalls also offer features like VPN support, NAT (Network Address Translation), and traffic shaping. These extra features turn the firewall into a network security platform that handles routing, encryption and access control in one box, which is why it remains central to network security even as the perimeter dissolves and cloud adoption grows.
The Evolution of Firewall Technology
Firewalls have been part of network security since the late 1980s. The first firewalls used simple packet filtering. By the early 2000s, stateful inspection firewalls became the norm. Now, next generation firewalls (NGFWs) add app awareness and AI-powered analysis. Each new generation added a deeper layer of inspection and control. Today, the term “firewall” covers everything from a basic iptables rule on a Linux box to a large enterprise appliance with deep packet inspection, sandboxing, and threat intelligence feeds. The core job remains the same: filter traffic, block potential threats, and protect the network from unauthorized access.
How a Firewall Works
Firewalls follow the same basic loop: inspect, decide, act. When a data packet arrives, the device reads its header, which contains key details: source and destination IP addresses, port numbers, protocol type, and sometimes the payload. The firewall compares these details against its rule set. If a rule matches, the device takes the action tied to that rule: allow, deny, or drop.
Rules, Policies, and Default Actions
A rule set is a list of conditions that tell the firewall what to do with each type of traffic. Rules run in order from top to bottom, and the device applies the first matching rule and ignores the rest, so rule order matters. A broad “allow all” rule at the top will override every block rule below it. A common practice is to put the most specific rules first and end with a default deny. A default deny rule blocks everything that no other rule covers. This approach follows the least-privilege principle and closes gaps that admins might miss.
Policies group rules into logical sets. A firm might have one policy for the DMZ, another for the LAN, and a third for guest Wi-Fi. Each policy reflects the trust level of that zone. The DMZ policy is strict because it faces the internet. The LAN policy is more open because it serves internal users. A good security strategy still applies controls inside the LAN to limit lateral movement if a breach occurs.
Stateless vs Stateful Processing
Early firewalls, called packet filtering firewalls, checked each data packet on its own. They looked at source and destination IP addresses, port numbers and protocol, then made a one-shot decision. This is called stateless filtering. It is fast but limited. Because the firewall has no memory of past data packets, it cannot tell if a packet is part of a valid session or a spoofed reply.
Stateful inspection firewalls solved this problem. They track the state of each connection, from the initial handshake to the final close. When a user inside the network starts a session, the device records it in a state table. Return data packets that match an existing session pass through without hitting every rule. Data packets that claim to be replies but have no matching session get dropped, which makes stateful firewalls much harder to fool than stateless filters. Enterprise firewalls use stateful inspection as a baseline.
Incoming and Outgoing Traffic Filtering
A firewall filters traffic in both directions. Incoming and outgoing traffic face different risks. Incoming traffic carries threats like port scans, malware payloads, and brute-force login attempts. The firewall blocks these by checking source and destination IP addresses, port numbers and matching against known bad IPs and signatures. Filtering outgoing network traffic catches a different set of risks. It stops data exfiltration, blocks malware phone-home calls, and enforces acceptable-use policies. Ignoring the outgoing side leaves a big gap, so a strong firewall monitors both directions with equal rigor.
Data packets are small chunks of information that travel across a network. Each packet has a header (with routing details like source and destination IP addresses, port numbers) and a payload (the actual content). A firewall reads the header, and sometimes the payload, to decide if the packet is safe.

Types of Firewalls Explained
Firewalls vary. Different types handle different layers of the network stack and offer different levels of protection. Knowing the types of firewalls helps you pick the right one for each part of your setup. Below is a breakdown of the major categories.
Packet Filtering Firewall
A packet filtering firewall is the simplest and oldest type. It checks each data packet against a rule set based on source and destination IP addresses, port numbers, and protocol. If the packet matches an allow rule, it passes. If not, it gets dropped. This type of firewall is fast and cheap, but it cannot see inside the packet payload, so it misses threats hidden in the data itself. Packet filtering firewalls work best as a first layer of defense, not as a standalone solution.
Stateful Inspection Firewalls
Stateful inspection firewalls add session tracking on top of packet filtering. They remember the state of each connection and let return traffic through only if it matches an active session. This makes them far more secure than basic filters, and they balance speed and security well. They still cannot inspect the content of data packets at the application layer. For that, you need a next generation firewall (NGFW).
Proxy Firewalls
A proxy firewall acts as a middleman. Instead of letting data packets flow straight through, it creates a separate connection on each side. The client talks to the proxy, and the proxy talks to the server. This breaks the direct link and gives the device full control over the traffic. Proxy firewalls can inspect packet content, cache data, and hide internal network details. They add latency because each packet goes through an extra hop, so they suit web traffic but may struggle with high-throughput workloads. Firms tend to use proxy firewalls for specific flows, like web browsing, rather than for all incoming and outgoing traffic. On the server side, a reverse proxy plays a similar middleman role, taking in web requests and passing them to the right backend.
Next Generation Firewall (NGFW)
A next generation firewall (NGFW) goes beyond basic packet and state checks. It adds deep packet inspection, app-level awareness, intrusion prevention, and threat intelligence feeds. With deep packet inspection, the firewall reads the payload, not just the header, to catch malware, exploits, and command-and-control traffic. App awareness lets the device tell the difference between, say, a video call and a file transfer running on the same port. Policies can then target a specific application rather than a port number.
Many enterprise firewalls sold today are next generation firewall (NGFW) products. They bundle anti-malware, URL filtering, sandboxing, and SSL/TLS inspection into one platform. Some also include AI-powered threat detection that learns traffic patterns and flags anomalies in real time. The trade-off is cost and complexity. A next generation firewall (NGFW) needs more compute power and more tuning than a simple stateful filter. For firms facing advanced threats, the extra coverage can be worth it.
Web Application Firewall (WAF)
A WAF sits in front of web apps and filters HTTP/HTTPS traffic. It guards against attacks like SQL injection, cross-site scripting, and API abuse. Unlike a network firewall, a WAF focuses on layer-7 threats aimed at a specific application. Firms that run customer-facing web apps commonly deploy both a network firewall at the perimeter and a WAF in front of each app. This layered approach covers network security and application security in one strategy.
Firewall as a Service (FWaaS)
FWaaS delivers firewall features from the cloud. Instead of buying a box, you subscribe to a cloud service that filters your traffic. All incoming and outgoing traffic routes through the provider’s points of presence. This model fits remote-first firms, branch offices, and multi-cloud setups well. It scales on demand and removes the need for hardware. The trade-offs are dependence on the provider’s uptime and the latency of routing traffic through a third party. FWaaS fits firms that are spread out and cloud-based.
| Type | OSI Layer | Session Tracking | Payload Inspection | App Awareness | Best For |
|---|---|---|---|---|---|
| Packet Filtering | L3, L4 | ✕ No | ✕ No | ✕ No | Basic perimeter filtering |
| Stateful Inspection | L3, L4 | ✓ Yes | ✕ No | ✕ No | Enterprise LAN/WAN |
| Proxy | L7 | ✓ Yes | ✓ Yes | ◐ Partial | Web traffic, content filtering |
| NGFW | L3, L7 | ✓ Yes | ✓ Yes | ✓ Yes | Full enterprise protection |
| WAF | L7 | ✓ Yes | ✓ Yes | ✓ Yes (web only) | Web app defense |
Firewall Architecture: Hardware, Software, and Cloud
Firewalls come in three main forms: hardware, software, and cloud. Each form fits a different use case, and many firms use a mix of all three.
Hardware Firewalls
A hardware firewall is a dedicated box that sits at the edge of a network. It has its own CPU, memory, and OS built for one job: filtering traffic. Because it runs on purpose-built hardware, it handles high throughput with low latency. Large firms place hardware firewalls at offices, data centers and branch sites. The downside is cost: high-end units are expensive and need physical space, power and hands-on upkeep. They remain common at high-traffic sites because of their throughput.
Software Firewalls
A software firewall runs on a standard server or endpoint. Major operating systems ship with a built-in host-based firewall: Windows Defender Firewall, iptables on Linux, pf on macOS. These host-based firewalls protect the device they run on, working alongside endpoint security agents. They are useful as a second layer behind a network firewall, but they share CPU and memory with the host, so heavy traffic can slow down the machine. Software firewalls also need per-device management, which gets complex at scale.
NAT and VPN Functions
Many firewalls also handle NAT and VPN duties. Network Address Translation hides internal IP addresses behind a single public IP, which stops outside scanners from mapping your internal network layout. It also saves public IP space. Every data packet leaving the network gets its source IP rewritten to the firewall’s public IP. Return traffic gets mapped back to the right internal host. This process is invisible to the user and keeps internal addresses hidden.
VPN support lets remote users connect to the internal network through an encrypted tunnel. The device acts as the VPN endpoint. It checks the user’s credentials, sets up the tunnel, and applies the same rule set to VPN traffic that it applies to LAN traffic. Remote workers then get the same level of threat protection as in-office staff. Without VPN on the firewall, firms need a separate VPN appliance, which adds cost and complexity. Having both functions in one box simplifies the setup and cuts the number of devices to manage.
Cloud and FWaaS Firewalls
Firewall as a Service (FWaaS) runs in the cloud. The vendor hosts and manages the device, and you route traffic through it. This model scales fast because you do not need to buy or rack hardware. It also works well for firms with remote workers, SaaS-heavy setups, or multi-cloud deployments. FWaaS supports cloud security strategies and fits into SASE (Secure Access Service Edge) designs where network security and networking merge in the cloud. The trade-off is dependency on the vendor’s uptime and the latency of routing traffic through an external point.
Talk to an ExpertNot sure your firewall rules still fit your network? Ask us for a review.Firewall Deployment Patterns for Network Security
Where you place a firewall in your network matters as much as which type you choose. Different patterns serve different goals. Below are common layouts and when to use each one.
Perimeter Firewall
The perimeter firewall sits at the edge of your network, between your internal LAN and the internet. It is the classic deployment pattern: incoming and outgoing network traffic passes through this single choke point. The firewall checks each data packet and applies the rule set before anything reaches internal systems. This pattern works well for firms with a clear network boundary, like a single office with on-premises servers. It breaks down when users work from home, apps live in the cloud, and the line between “inside” and “outside” blurs. In those cases, you need more than one firewall, and more than one pattern.
DMZ and Dual-Firewall Layouts
A DMZ (demilitarized zone) puts public-facing servers, like web servers, email gateways and DNS, in a separate zone between two firewalls. The outer firewall filters traffic from the internet to the DMZ. The inner firewall filters traffic from the DMZ to the LAN. This way, if an attacker breaches a DMZ server, they still face another firewall before reaching sensitive internal systems. Dual-firewall DMZ layouts are common for firms that host their own web apps and email. They add cost but reduce the blast radius of a breach.
Internal Segmentation
An internal segmentation firewall sits inside the network. It divides the LAN into zones, for example, separating finance from engineering, or servers from workstations. This pattern limits lateral movement. If malware infects one zone, the device stops it from spreading to others. Internal segmentation is a core part of Zero Trust designs. It treats each zone as untrusted and applies the same rigor to east-west traffic that a perimeter firewall applies to north-south traffic. If a phishing email compromises a workstation, segmentation stops the attacker from hopping to the finance server.
Deep Packet Inspection and Application Awareness
Deep packet inspection separates modern firewalls from legacy filters. The device reads the full payload of each data packet, not just the header, which lets it catch malware, exploits, and data leaks that header-only checks would miss. A hacker might tunnel a command-and-control channel inside normal HTTPS traffic. A basic firewall sees port 443 and lets it through, while a firewall with deep packet inspection breaks open the SSL session, reads the content, and spots the malicious payload.
Application awareness builds on deep packet inspection. It lets the firewall tell one app from another, even when both use the same port. A next generation firewall (NGFW) can tell the difference between a Zoom call and a Dropbox upload on port 443. Admins can write rules for a specific application (“allow Zoom, block Dropbox”) instead of blanket port rules, so policies match business intent.
Together, deep packet inspection and app awareness give the device visibility into outgoing traffic that breaks content rules, not just headers. This is critical for stopping data exfiltration, where an attacker uses an allowed protocol to sneak data out. It is also key for enforcing acceptable-use policies, like blocking social media during work hours or flagging large uploads to personal cloud storage.
Firewalls and AI
AI-powered firewalls use machine learning to go beyond static rule sets. Instead of relying only on human-written rules, an AI-powered firewall learns from traffic patterns. It builds a baseline of “normal” and flags anything that deviates. This helps catch zero-day attacks and novel threats that a rule set does not cover, and the model improves as it sees more data.
AI-powered features show up in several areas. Automated rule tuning adjusts the rule set based on real traffic patterns, closing gaps that manual reviews might miss or take too long to find. Threat scoring ranks alerts by risk so analysts focus on the worst ones first. Behavioral analysis watches user and device patterns to spot compromised accounts or insider threats.
AI has limits. A model trained on bad data produces bad results, false positives can flood the SOC, and attackers use AI to craft evasion techniques. Treat AI-powered features as an aid, not a replacement for solid rules, patching and network segmentation. Use AI to filter noise and surface the alerts that matter, and keep humans in the loop for final calls on complex incidents.
Firewall Rules for AI Agents
AI agents and MCP servers make outbound calls on their own, so they need firewall rules like any other workload. The MCP Security Best Practices warn about server-side request forgery and advise limiting where servers can connect. Allow agent hosts to reach only the APIs they need, block internal ranges they do not need, and log every connection.

Malware That Calls AI Models
In November 2025, Google’s Threat Intelligence Group described malware such as PROMPTFLUX that asks an AI model to rewrite its own code while it runs. Signatures struggle with code that keeps changing. Still, a firewall that blocks servers from calling AI APIs they have no reason to use cuts that malware off from its helper.
Patch the Firewall Itself
Firewalls are edge devices, and attackers target them hard. Verizon’s 2025 DBIR found that edge devices and VPNs made up 22% of vulnerability exploitation targets, and that the median time to fully fix edge device flaws was 32 days. Treat firewall firmware patches as urgent, not a quarterly chore. Our guide to rogue AI agents covers how to contain agents that misbehave.
Common Firewall Threats and How to Stop Them
A firewall blocks many threats, but it also faces threats itself. Attackers probe firewalls for misconfigurations, weak rules, and bypass routes. Knowing these common threats helps you harden your firewall setup and rule set against them before attackers strike.
Misconfigs and Overly Broad Rules
A common firewall failure is a bad rule. An “allow any any” rule left over from testing, an unused port left open or a policy that allows all outbound traffic gives attackers a free path. Regular audits of the rule set catch these gaps. Remove stale rules, tighten overly broad ones, and log every change. Treat the policy set as code: version it, review it, and test it before pushing live. Tools like Terraform and Ansible can automate firewall rule deploys and enforce peer review through pull requests.
Evasion Techniques
Attackers use several tricks to slip past a firewall. Tunneling hides malicious traffic inside allowed protocols like HTTPS or DNS. Fragmentation splits an attack across tiny data packets that a firewall may reassemble incorrectly. Encrypted traffic blinds any firewall that does not do SSL/TLS inspection. To counter these, deploy a next generation firewall (NGFW) with deep packet inspection, SSL decryption, and protocol anomaly detection. Keep firmware and signatures up to date so the device can spot the latest evasion tricks.
Firewall Best Practices for Network Security
Deploying a firewall is only the start. How you configure and manage it decides whether it protects you. These practices help you avoid common pitfalls.
Design and Rule Management
First, start with a default-deny policy. Block everything, then open only what the business needs. This is safer than starting open and trying to close gaps. Second, keep your rule set clean. Review rules quarterly. Remove any rule that no one can explain or that serves a retired app. Third, use zones. Split your network into trust zones (DMZ, LAN, guest, servers) and write policies per zone. This limits what happens if one zone gets breached.
Fourth, log everything: each allow and each deny. Feed these logs into a SIEM so you can spot trends, run forensics, and meet compliance requirements. Fifth, test your rules. Run penetration tests against the device at least once a year; they reveal gaps that rule reviews miss. Use the results to tune rules and close holes before attackers find them. Sixth, document every policy. Write down why each rule exists, who requested it, and when it was last reviewed. This context helps future admins decide if a rule is still needed or if it should be retired.
Ongoing Operations
Patch the appliance firmware on schedule. Firewall vendors release security patches for bugs that attackers exploit, and delaying them leaves a known hole. Back up the device config before each change. A bad rule push can take down the network. With a backup, you can roll back quickly. Automate backups so they happen with each change.
Monitor device health metrics: CPU load, memory use, session count, and throughput. An appliance running near full CPU may not process traffic fast enough and can drop legitimate data packets. Consider managed cybersecurity services if your team lacks the capacity to monitor around the clock. Plan capacity so the firewall handles peak loads with room to spare, and size the next refresh for expected growth.
Treat every firewall rule change like a code deploy. Use a change ticket, peer review, and a rollback plan. Uncontrolled changes are a leading cause of firewall misconfigurations and outages.
Firewall Logging, Monitoring, and Incident Response
A firewall generates a large volume of log data. Every allow, deny, and drop creates a log entry. These entries record source and destination IP addresses, port numbers, protocol, action, timestamp, and sometimes the matched rule. This data is valuable to security teams only if someone looks at it.
What to Monitor
Focus on a few high-value patterns. First, watch for repeated denied connections from the same source IP. This can signal a port scan or brute-force attempt. Second, monitor outbound connections to unusual destinations. A workstation calling a server in a country where you have no business may be a malware callback. Third, track rule-change logs. Any time someone adds, edits, or deletes a firewall rule, the change should be logged and reviewed. Unauthorized rule changes are a red flag for insider threats or compromised admin accounts.
Tying Logs to Incident Response
When a security incident hits, firewall logs are an early place analysts look. They show who talked to whom, on what port, and when. This data helps build a timeline of the attack. Feed firewall logs into your SOC platform in real time. Set up alerts for the patterns above so the team can respond quickly. Keep logs as long as forensics and compliance need; old logs help answer “How did they get in, and when did it start?”
Firewall and Zero Trust: Beyond the Perimeter
The old model of network security put a firewall at the edge and trusted everything inside. Zero Trust flips that model: verify each request, wherever the traffic comes from. The firewall still matters, but its role changes. Instead of guarding one big perimeter, it enforces micro-segmentation across the entire network. Every zone, every app, and every user session gets its own set of rules.
Micro-segmentation means the firewall creates tiny trust zones around each workload or user group. If an attacker breaches one zone, the device blocks them from moving to the next. This limits the blast radius of a breach. A next generation firewall (NGFW) with identity-based policies can tie access rules to specific users and their devices, not just fixed IP addresses. This way, the same device gets different access based on who is logged in and what they are trying to reach.
Zero Trust also pushes firewall controls closer to the workload. Instead of one big box at the edge, firms deploy distributed firewalls, in the cloud, on endpoints, and inside the network fabric. This layered approach filters traffic at many hops, not just at the front door. Combined with continuous authentication and least-privilege access, this model gives stronger network security than a single perimeter firewall. It demands more policy work up front but shrinks the blast radius when a breach happens.
How to Choose the Right Firewall
Picking a firewall starts with knowing your network. Map out your traffic flows, workload types, and trust boundaries. Then match those needs to a firewall type. Small offices with basic web access may do fine with a stateful inspection firewall. Mid-size firms with cloud apps and remote workers tend to need a next generation firewall (NGFW). Large enterprises with complex multi-cloud setups commonly layer NGFW, WAF, and FWaaS together.
Look at throughput specs. The device must handle your peak traffic without dropping data packets. Check the throughput with all features turned on: deep packet inspection, SSL decryption, and IPS. Vendors may quote numbers with features off, which inflates the spec. Also check concurrent session limits and new-session-per-second rates. If these numbers are too low for your load, the firewall will become a bottleneck.
Management, Integration, and Cost
Third, consider management and integration. Does the device have a central console that works across all your sites? Can it push rules to cloud and on-premises nodes from one place? Does it feed logs into your SIEM and pull threat intelligence from your feeds? These factors can matter more than raw specs, because a firewall that is hard to manage ends up with stale rules.
Compliance is another factor: check that the firewall supports the controls your frameworks ask for. Factor in total cost of ownership: hardware, licenses, support, power, and the time your team spends managing it. A cheaper box that needs more admin hours may cost more in the end. Finally, plan for growth so you avoid an expensive mid-cycle upgrade.
Conclusion
A firewall is a network security system that sits between trusted and untrusted networks. It checks each data packet against a rule set and blocks unauthorized access, potential threats and outgoing traffic that breaks policy. From the basic packet filtering firewall to the modern next generation firewall (NGFW) with deep packet inspection and AI-powered threat detection, the types of firewalls have evolved to match the threats they face.
A firewall is only as strong as its rules and the team that manages them, so default-deny policies, regular audits, patching and logging matter. As networks shift to Zero Trust models, the device’s role expands from perimeter guard to micro-segmentation enforcer. Whether you deploy hardware, software, or cloud-based firewalls, the goal stays the same: control incoming and outgoing traffic, block potential threats, and keep your network safe.
Our SolutionEndpoint, Network and Zero Trust SecurityFrequently Asked Questions About Firewalls
What is the difference between a firewall and antivirus?
Do I need a hardware firewall for a small office?
What is the difference between NGFW and a traditional firewall?
Can a firewall stop all cyberattacks?
How often should I audit firewall rules?
Do AI agents need firewall rules?
Can firewalls use AI?
References
- Firewall guidance: NIST SP 800-41 Rev. 1, Guidelines on Firewalls and Firewall Policy
- Edge device exploitation: Verizon, 2025 Data Breach Investigations Report
- AI agent egress: Model Context Protocol, Security Best Practices
Get the Latest Terms & Insights.
New encyclopedia terms, threat intelligence, and architecture decisions, by email.
