Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Is a Firewall and How Does It Work?

Technology
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 5, 2026
6 min read

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.

Table of Contents

  • What a firewall does
  • How packet filtering and stateful inspection work
  • Inbound and outbound rules and the default policy
  • Types of firewalls you will meet
    • Host-based firewalls
    • Network firewalls
    • Cloud firewalls and web application firewalls
  • A simple example with ufw
  • What a firewall cannot protect you from
  • Frequently Asked Questions
    • Do I need a firewall if I already have a router?
    • Is Windows Defender Firewall good enough?
    • What is the difference between a firewall and antivirus software?
    • Does a firewall make me anonymous?
  • Summary
  • Related Articles

What a firewall does

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.

How packet filtering and stateful inspection work

Firewalls have become smarter over the decades. The main generations are:

TypeWhat it checksStrengthLimit
Packet filterSource, destination, protocol and port of each packet on its ownFast and simpleNo memory of earlier packets
Stateful firewallThe same fields plus the state of the connectionAllows replies to connections you started, blocks unsolicited onesDoes not understand application content
Proxy or application firewallThe content of a specific protocol such as HTTPCan block specific requestsSlower and protocol specific
Next-generation firewall (NGFW)Applications, users, intrusion signatures and sometimes TLS trafficPolicies by application and identityCosts 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.

Inbound and outbound rules and the default policy

Rules apply to two directions:

  • Inbound rules control traffic coming to your device or network from outside.
  • Outbound rules control traffic leaving it.

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.

Types of firewalls you will meet

Host-based firewalls

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.

Network firewalls

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 firewalls and web application firewalls

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.

A simple example with ufw

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:

bash

Example output of the last command:

text

Be careful to allow your SSH port before enabling the firewall on a remote machine, otherwise you lock yourself out.

What a firewall cannot protect you from

A firewall is not a complete security solution. It does not stop:

  • Phishing, where you willingly type a password into a fake site.
  • Malware you download and run, because that traffic looks like a normal outbound connection.
  • Malicious attachments or infected USB drives.
  • Weak or reused passwords.
  • Attacks that travel inside allowed traffic, such as a flaw in a web app you have exposed on port 443.

Use a firewall together with software updates, strong unique passwords, multi-factor authentication, backups and an up-to-date antivirus or endpoint protection tool.

Frequently Asked Questions

Do I need a firewall if I already have a router?

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.

Is Windows Defender Firewall good enough?

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.

What is the difference between a firewall and antivirus software?

A firewall controls network connections, while antivirus inspects files and processes for malware. They protect against different problems and work best together.

Does a firewall make me anonymous?

No. A firewall filters traffic but does not hide your IP address or encrypt your browsing. A VPN or Tor addresses different needs.

Summary

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.

Related Articles

  • What Are Browser Privacy Settings and How Do You Use Them?
  • How Do You Secure Your Home Wi-Fi Router?
  • Learn Technology: Complete Study Roadmap for Beginners
Share