Firewalls function by inspecting packets of data as they enter or leave your network. They use a set of security rules to determine whether to allow or block the traffic. These rules can be based on various factors such as IP addresses, domain names, protocols, ports, and keywords. Firewalls can be either hardware-based or software-based, and many organizations use a combination of both for enhanced security.