Hubs are old network devices that have been replaced by switches. As such, they basically function in the same manner, connecting multiple computers and allowing the flow of data across these computers. Routers, on the other hand, are simplified computers that can control the flow of data that passes through it.
Routers come in many shapes and sizes; the most common nowadays is the set-top device that is just about the same size as a switch or a hub. It is the cheapest and most convenient set-up to use but is also the one with the most minimal amount of features. Routers are usually placed in between your local network and the Internet; this is to ensure that all traffic that goes in and out of the network passes through the router since most routers also have built-in security measures that help protect your network. Features like Firewalls keep the network secure by rejecting invalid or suspicious packets. Another key feature that routers commonly have is Port Forwarding. Port Forwarding allows you to indicate which computers should receive packets that use a certain port. This is very essential especially when you are running multiple services on different computers in the same network.
A hub is simply a layer device that allows computers to send information to each other; they do not have any installed software that could be configured or set-up. Hubs are plug and play devices that would work right out of the box as long as all the computers connected to it are configured correctly. Hubs have been phased out in favor of the more advanced switches due to a couple of disadvantages. The first is that computers connected to a hub compete for the available bandwidth and is oftentimes becomes a bottleneck when users send or receive large amounts of data. The problem is negligible in very small numbers of computers but becomes very apparent as more computers are attached to the network. The second problem is collision, that occurs when two or more computers transmit data at the same time. Since hubs do not have the capability to transmit multiple packets at the same time, it needs to monitor whenever a collision occurs and correct it in order to maintain data integrity. Switches do not have these problems, thus it has replaced the hub in most areas.
Routers and the switches, the replacement of hubs, are very important components of a network; routers for connecting your network to the internet, and switches for connecting your computers to each other and your router.