What is a firewall, and what does it do?

What is a firewall? A firewall is a device or program that checks network traffic against a set of rules and blocks what isn’t allowed. Its main job is to stop unwanted connections from reaching your computer or network. Windows and macOS both include one.

Last updated November 20, 2026

Dark title card reading "What is a firewall, and what does it do?" under the label Security Guide

The short version

  • A firewall filters traffic going into and out of a device or network, using rules based on things like IP addresses, ports and apps.
  • There are 2 broad kinds: network (hardware) firewalls that protect a whole network, and software firewalls that run on a single computer.
  • Windows Firewall is turned on by default, according to Microsoft. On a Mac, you can check and turn on the firewall in System Settings under Network.
  • A firewall isn’t antivirus. The US Cybersecurity and Infrastructure Security Agency (CISA) says it doesn’t guarantee your computer won’t be attacked.

What is a firewall, in plain terms

The US National Institute of Standards and Technology (NIST) defines a firewall as “a gateway that limits access between networks in accordance with local security policy.” Another NIST definition, from its firewall guidelines (SP 800-41), calls it “a device or program that controls the flow of network traffic between networks or hosts that employ differing security postures.”

Put simply, a firewall sits between your device or network and everything else. It looks at each piece of traffic, compares it with its rules and lets it through or blocks it. CISA says firewalls can block traffic from certain addresses, applications or ports while letting the data you need get through.

How does a firewall work?

Every firewall works from a list of rules, which NIST calls a ruleset. A rule might allow web traffic, block a particular address or stop a specific app from connecting. Microsoft says Windows Firewall rules can filter traffic by source and destination IP address, IP protocol, port number and the app or service involved.

Firewalls can filter in both directions. NIST calls checking incoming traffic “ingress filtering” and checking outgoing traffic “egress filtering.”

Microsoft says the default behavior of Windows Firewall is to:

For organizations, NIST recommends going further with a policy it calls “deny by default”: block all inbound and outbound traffic that the firewall policy hasn’t expressly permitted.

Types of firewalls

NIST describes several firewall technologies. It says packet filtering is at the core of most modern firewalls and that many firewalls combine multiple features.

TypeWhat it checks
Packet filter (stateless)Each packet’s addresses, protocol and ports, without tracking connections
Stateful inspectionThe same details, plus whether a packet belongs to a connection it’s already tracking
Application firewallHow an application behaves over the network, such as blocking a forbidden type of email attachment
Application-proxy gatewayTraffic passed through a go-between, so the 2 sides never connect directly
Web application firewallAttacks aimed at a web server, from a position in front of that server

Stateless vs stateful firewalls

A stateless packet filter judges each packet on its own. NIST says these filters can’t link multiple requests in the same session and that few firewalls sold today only do stateless filtering.

A stateful firewall keeps a state table of open connections. NIST gives an example: an attacker could send a packet with a header claiming it’s part of an established connection. A stateful firewall first checks its table to confirm that the connection really exists.

Unified threat management

Some products bundle a firewall with other security tools. NIST says a typical unified threat management (UTM) system combines a firewall with malware detection and removal plus detection and blocking of suspicious network probes.

Hardware vs software firewalls

CISA splits firewalls into 2 groups:

Both have limits. CISA says hardware firewalls need trained people to set them up and maintain them. It also says a software firewall runs on the system it’s protecting, so it may be less effective at detecting threats, and each computer’s firewall has to be managed separately. NIST adds that an attacker who gains administrator access to a computer can disable or get around its firewall.

That’s why the 2 kinds work best together. NIST says a home firewall appliance is still a valuable extra layer even when every computer runs its own firewall: if a computer’s firewall fails, is turned off or is set up wrong, the appliance can still block unauthorized connections from outside.

One common confusion: network address translation (NAT) is sometimes thought of as a firewall technology, but NIST says it’s actually a routing technology. Its guidelines say NAT “should be considered a form of routing, not a type of firewall.”

Do you need a firewall?

Yes, and you probably already have one. Microsoft says Windows Firewall is included with the operating system and enabled by default on all Windows editions. macOS includes a firewall too, which you can turn on in System Settings.

For most people the job is simply to leave the built-in firewall on, rather than to buy one. CISA says most firewalls come preconfigured but that default settings tend to be less restrictive, so it recommends reading the documentation to check that the settings suit you.

A firewall matters most on networks you don’t control. Microsoft’s example is coffee shop Wi-Fi, where most other devices belong to strangers. Windows Firewall can apply a public network profile there and a private profile at home, and Microsoft says this lets you use more restrictive settings on public networks.

How to check your firewall on Windows

Microsoft’s steps for Windows 11 and Windows 10:

  1. Open the Windows Security app and select Firewall & network protection.
  2. Select a network profile: Domain network, Private network or Public network. Windows Security shows which type you’re connected to.
  3. Under Microsoft Defender Firewall, make sure the switch is set to On.

Microsoft warns that turning the firewall off could make your device more vulnerable to unauthorized access. If an app you need is blocked, it suggests allowing that app through the firewall instead. On a work PC, your organization’s policies might stop you from changing these settings.

Allowing apps: Microsoft calls both ways of letting an app through risky, but says adding the app to the allowed list is safer than opening a port. A port stays open until you close it, while an allowed app opens the ports it needs only when it needs them. Microsoft also says never to allow an app you don’t recognize.

How to turn on the firewall on a Mac

Apple’s steps:

  1. Choose Apple menu > System Settings, click Network in the sidebar, then click Firewall. You may need to scroll down.
  2. Turn on Firewall.
  3. To choose which apps and services can accept connections, click Options.

Apple says the Mac firewall can protect against unwanted contact started by other computers. Some things can still get through: Apple says turning on a sharing service such as file sharing opens a port for it, and some apps that don’t appear in the list, including system services and digitally signed apps opened automatically by other apps, may have access. When an app that isn’t on your list gets a connection attempt, macOS asks whether to allow or deny it.

Firewall vs antivirus vs VPN

These 3 tools do different jobs, and you can use all of them at once.

ToolWhat it does
FirewallFilters network traffic and blocks connections its rules don’t allow
AntivirusScans the device for viruses, malware and ransomware
VPNEncrypts traffic between your device and a VPN gateway or server

CISA says a firewall mainly guards against malicious traffic, not malware you install or run yourself, which is why it recommends using a firewall alongside antivirus software. On Windows, Microsoft says the Virus & threat protection page of the Windows Security app helps protect your device against threats such as viruses, malware and ransomware. Our guide to antivirus for older PCs covers whether the built-in Microsoft Defender Antivirus is enough.

NIST says VPNs use extra protocols to encrypt traffic and provide user authentication and integrity checking, and many business firewalls include VPN features. Read what a VPN is for when it helps.

What a firewall can’t do

A firewall is one layer of protection, not the whole thing. CISA puts it directly: “Firewalls do not guarantee that your computer will not be attacked.”

Frequently asked questions

Is a firewall free?

You don’t need to pay for one to get started. Microsoft says Windows Firewall is included with the operating system, so no extra hardware or software is required. Apple’s Mac User Guide shows how to turn on the firewall built into macOS.

Can a firewall be hardware?

Yes. CISA describes hardware firewalls as physical devices placed between your computers and the internet. NIST says some teleworkers protect their home networks with a small device it calls a firewall appliance or firewall router.

What is a firewall rule?

A rule tells the firewall what to allow or block and under what conditions. Microsoft says Windows Firewall rules can match traffic by app, service or program name, by source and destination IP address and by port, among other conditions.

What is a firewall port?

Firewall rules often refer to ports. NIST’s example is TCP port 80 as the destination port of a web server. Microsoft says opening a port in Windows Firewall allows traffic into or out of your device and makes it less secure.

Should I turn off my firewall?

No. Microsoft says turning off Windows Firewall could make your device more vulnerable and suggests allowing a blocked app through the firewall instead. If settings were changed and apps stop working, the Windows Security app has an option to restore the firewall defaults.

More in Security

Sources