Hubs and switches are different types of network equipment that connect devices. They differ in the way that they pass on the network traffic that they receive.
The term "hub" is sometimes used to refer to any piece of network equipment that connects PCs together, but it actually refers to a multi-port repeater. This type of device simply passes on (repeats) all the information it receives, so that all devices connected to its ports receive that information.
Hubs repeat everything they receive and can be used to extend the network. However, this can result in a lot of unnecessary traffic being sent to all devices on the network. Hubs pass on traffic to the network regardless of the intended destination; the PCs to which the packets are sent use the address information in each packet to work out which packets are meant for them. In a small network repeating is not a problem but for a larger, more heavily used network, another piece of networking equipment (such as a switch) may be required to help reduce the amount of unnecessary traffic being generated.
Switches control the flow of network traffic based on the address information in each packet. A switch learns which devices are connected to its ports (by monitoring the packets it receives), and then forwards on packets to the appropriate port only. This allows simultaneous communication across the switch, improving bandwidth.
This switching operation reduces the amount of unnecessary traffic that would have occurred if the same information had been sent from every port (as with a hub).
Switches and hubs are often used in the same network; the hubs extend the network by providing more ports, and the switches divide the network into smaller, less congested sections.