A firewall is a hardware or software barrier that protects private networks from unauthorized access from outside networks. There are two main types - hardware firewalls which are physical devices installed between networks, and software firewalls which are installed on individual computers. Common firewall techniques include packet filtering, application gateways, circuit-level gateways, and bastion hosts. A firewall examines all incoming and outgoing network traffic and blocks unauthorized traffic based on predefined security rules.