A firewall is a security control that sits between networks or devices and decides which network traffic is allowed and which is blocked, based on rules. Understanding what a firewall is helps you see why it is one of the first lines of defence: it inspects connection attempts, compares them with its rules, and either lets them through or drops them.
A firewall can be software on your laptop, a feature built into your home router, or a dedicated appliance or cloud service in a company network. All of them do the same basic job: enforce a policy about who may talk to what.
Every piece of data on a network travels in packets. Each packet carries a source address, a destination address, a protocol (such as TCP or UDP) and port numbers. A port identifies the service on a machine: web servers listen on 443 for HTTPS, mail servers on 25 or 587, and SSH on 22.
A firewall reads this information and applies a list of rules from top to bottom. A rule might say "allow TCP to port 443" or "block everything from this address range". The first rule that matches decides the packet's fate. If nothing matches, a default policy applies.
Think of it as a security desk at a building entrance. The desk does not know what is inside every parcel, but it checks who is coming, where they are going and whether they are on the list.
Firewalls have become smarter over the decades. The main generations are:
| Type | What it checks | Strength | Limit |
|---|---|---|---|
| Packet filter | Source, destination, protocol and port of each packet on its own | Fast and simple | No memory of earlier packets |
| Stateful firewall | The same fields plus the state of the connection | Allows replies to connections you started, blocks unsolicited ones | Does not understand application content |
| Proxy or application firewall | The content of a specific protocol such as HTTP | Can block specific requests | Slower and protocol specific |
| Next-generation firewall (NGFW) | Applications, users, intrusion signatures and sometimes TLS traffic | Policies by application and identity | Costs more and needs tuning |
Stateful inspection is the model almost every home router and operating-system firewall uses. When your browser opens a connection to a website, the firewall records it in a connection table. The website's replies match that entry and are allowed in. A packet that arrives from the internet with no matching entry is treated as unsolicited and dropped.
Rules apply to two directions:
Most consumer firewalls use "deny inbound by default, allow outbound by default". That means nothing from the internet can start a conversation with your computer unless you explicitly open a port, while your own apps can reach the internet freely. Stricter environments also restrict outbound traffic, which can stop malware from contacting its controller.
The safest design is a default-deny policy: block everything and allow only the specific traffic you need. A default-allow policy forces you to list every bad thing, which is impossible.
These run on the device itself. Windows includes Windows Defender Firewall, macOS has an application firewall, and Linux offers nftables with front ends such as ufw and firewalld. A host firewall protects the device even on a hostile network like a cafe Wi-Fi.
A network firewall protects a whole network. Your home router performs network address translation (NAT) and stateful filtering, which already blocks most unsolicited inbound traffic. Companies use dedicated appliances or virtual firewalls that separate the internet, office network and server networks.
Cloud providers offer security groups and network ACLs that act as virtual firewalls for servers. A web application firewall (WAF) is a specialised proxy that inspects HTTP requests to a website and blocks attacks such as SQL injection or cross-site scripting. A WAF complements a network firewall; it does not replace it.
On Ubuntu and many Linux systems, ufw (Uncomplicated Firewall) makes host rules readable. These commands set a default-deny policy, allow SSH and HTTPS, and turn the firewall on:
Example output of the last command:
Be careful to allow your SSH port before enabling the firewall on a remote machine, otherwise you lock yourself out.
A firewall is not a complete security solution. It does not stop:
Use a firewall together with software updates, strong unique passwords, multi-factor authentication, backups and an up-to-date antivirus or endpoint protection tool.
Yes, keeping both is wise. The router protects the network from unsolicited inbound traffic, while the host firewall protects your device on other networks and can control which apps connect out.
For most home users, yes. It is enabled by default, blocks unsolicited inbound connections and prompts you when an app wants to accept connections. Leave it on and avoid disabling it to "fix" a problem.
A firewall controls network connections, while antivirus inspects files and processes for malware. They protect against different problems and work best together.
No. A firewall filters traffic but does not hide your IP address or encrypt your browsing. A VPN or Tor addresses different needs.
A firewall enforces rules about which network traffic may enter or leave a device or network. Modern firewalls track connection state, can work per application, and run on devices, routers, appliances and in the cloud. Use a default-deny approach, keep the firewall enabled, and remember that it is one layer among several, not a replacement for updates, good passwords and careful behaviour.