Both the Ethernet hub and the Ethernet switch are used for computer networking, but understanding how they differ in their message-passing will help you understand when to prefer a hub over a switch. Hubs operate at the Physical Layer---Layer 1 of the Open Systems Interconnect (OSI) Reference Model. Switches perform the basic functions a hub performs, but also provide a Layer 2 filtering function that's either valuable or not---depending upon your needs.
Media Access (MAC) Addresses
Each Ethernet Network Interface Card (NIC) on a given network has a unique address on the Physical Layer---its MAC Address. Though the world has long since run out of unique Ethernet addresses the chances of having a duplicate on your local area network are very small.
Addressing an Ethernet Message
Specific: When a message is passed to a specific machine, that NIC's unique MAC Address is used, e.g. 08-00-2B-FC-A5-D9. Broadcast: When a message is passed to "everyone" on an Ethernet network, the address put on the packet is the Broadcast MAC address: FF-FF-FF-FF-FF-FF.
Repeating vs. Switching
Hubs, sometimes even called repeaters, just replicate every packet they receive to all network ports connected. Every packet is treated as though it were sent to the Broadcast Address.
More expensive and more capable, switches learn which MAC address is connected to which port and forward to those ports only the packets addressed to those NICs.
Hub: All NICs attached to an Ethernet Hub see all the packets destined for everyone attached to that Hub.
Switch: NICs never see packets addressed to each other, though they will still see packets addressed to the Broadcast address (FF-FF-FF-FF-FF-FF).
Visibility: Using an hub allows you to eavesdrop on conversations with a network protocol analyzer, often called a "sniffer".
Cost: Because hubs are less complicated, they tend to cost less per port than switches.
Client Performance: Because any given system attached to a switch sees only information explicitly addressed to its NIC, there is less overhead time spent throwing away packets that it does not need to read.
Higher Throughput: Because only relevant traffic is sent down any given network port, each NIC gets its own packets delivered to the switch independently of each other NIC attached to that switch. This means a switch can manage a larger total volume of data in transit at any given time.
Hub: Because they repeat all traffic they receive on all attached ports each connected NIC will have a more difficult time getting its traffic onto the network. Whenever one NIC sends a message, all others must wait for it to pass before they get their own message onto the network.
Switch: Unless the switch is expensive enough to include "port mirroring" capability, a sniffer is of limited use on a switch because the switch automatically filters out the traffic the sniffer would like to get.