Firewalls can be implemented in hardware, software or a combination of both.
Firewalls sit between the user’s computer and the external network, examining both the incoming and outgoing traffic, checking what has been requested and received.
The checks are to ensure that traffic (data) meets a given set of criteria (rules).
Any traffic (data) that doesn’t meet the criteria is filtered and stopped.
Firewall software will warn/ask the user when unknown or new software tries to access external data sources.