A firewall is a security device (hardware or software) that monitors and controls incoming and outgoing network traffic based on predefined security rules. It acts as a barrier between trusted and untrusted networks, blocking unauthorized access while allowing legitimate communication.