Stateful inspection firewalls analyze packets at all layers of the network protocol stack. They maintain a state table that records all active connections, including details like IP addresses, port numbers, and sequence numbers. When a packet enters the network, the firewall checks it against this state table to determine whether it is part of an established connection or a new request. This comprehensive traffic analysis allows the firewall to make more precise filtering decisions.