A switch will read packet headers and identify which machines are connected to which port based on the information they send. Any packets addressed to those machines will only get sent to that port of the switch.
A router looks at packet headers to determine which port it needs to forward a packet through, and also will translate packets between different protocols if needed. A router can also define subnets and will filter traffic as needed. Routers usually include DHCP, port forwarding capabilities and a whole host of other things usually controlled by software and therefore user customizable.
Hubs, Switches, Routers
A Hub is, in its simplest form, just like a mains multiplug unit. There is no intelligence or circuitry in it. More complex units may incorporate an amplifier or repeater. The network signal goes into one port and out of all the others. This is a Layer 1 device.
A Switch has a small level of intelligence, in that it can open a message, check the IP address, and direct the message packets to the port on which the device with that IP address resides. It cannot modify IP addresses or see addresses outside of the range of the 'home' network. This is a Layer 2 device.
A Router can read IP addresses, and direct the messages to another network with different IP addresses to the originating network. The Router software can build up an address table, so that it 'knows' where other devices are. This is a Layer 3 device.
CT