A firewall is hardware or software that controls access between private and public networks to protect private networks from unauthorized access. There are three main types of firewalls: packet filtering firewalls check each packet at the network layer; circuit-level firewalls monitor connections at the session layer; and application-level firewalls act as a proxy for specific applications like FTP. Firewalls can block unauthorized traffic and audit network activity to restrict access and detect abnormal behavior.