Hubs, switches and routers confused the crap out of me when I was first learning about networking. I just didn't understand what the differences were between three boxes that looked almost exactly the same, it just didn't make sense. Well now I know the differences and so can you!
Hubs
Simply Put...
Hubs are dumb. Dumb as in without brains and let me tell you why: All they do is repeat what they hear. Whatever comes into one port of a hub is re-broadcasted out every other port. That's it, that's all there is to a hub.
I've seen many analogies relating to hubs and there are several good ones. You can think of a hub as a chat room where any device plugged into it can see conversations that other devices are having, regardless of whether or not it involves them. You can think of a hub as a power strip where it simply repeats a signal. Or you can think of a hub as a dumb networking device, because that's what it is.
Hubs definitely have their place in networking, however. There are times when a hub is actually the most practical solution for a particular situation, and there are times when a hub may even provide quicker speeds than other equipment. However, I recommend using them with discretion. I recently discovered that one of my college's entire computer labs is running on a hub (or multiple hubs) and by opening a packet sniffing program like Ethereal I was able to see every last packet flowing to and from the internet, including sensitive information like passwords. This isn't the greatest security model, so you probably wouldn't want to use a hub in such a situation without a dang good reason.
For the Nerds
Aside from the security issue mentioned above, hubs just have some serious drawbacks. By design, a hub is just one gigantic Collision Domain, which means exactly what it sounds like: It's a place where electrical signals can potentially collide into each other. Think of a collision domain like a big cave in the side of a cliff with 4 or 5 entrances. If one person stands just outside of each cave entrance and tries to communicate with another person, they obviously have to yell into the cave, and it becomes apparent that only one person can talk through the cave at a time. This is essentially what a collision domain is, it means that only one device can communicate at any given time. To see where this really becomes an issue, expand the number of cave entrances in your head to 24 or 48 with people still trying to communicate with each other, it can get messy. With this in mind, think back to the speed ratings we see in networking like 10 mbps. Since a hub is just one collision domain this 10 mbps speed ends up getting shared by however many devices are using it, which means the speed ends up being considerably slower than 10 mbps in most instances.
Another drawback inherent to hubs is the constant collision of data due to this single collision domain. Imagine having a couple dozen devices on a single collision domain all trying to use it at the same time, it's chaotic. Luckily for us, Ethernet networks employ a technique known as CSMA/CD or Carrier Sense Multiple Access/Collision Detection. Without going into too much needless detail, CSMA/CD is the process by which devices listen to the network to determine if it's being used and transmit their data when they think it's safe. In the event that two devices send signals at the exact same time (a collision), they cancel each other out with a "jam sequence" to clear the line and wait a random amount of time before retransmitting. If you'd like more detail you can visit this page but needless to say that even with CSMA/CD in action, a single collision domain just isn't the greatest environment for devices to be communicating in.
Bridges
This would be a good place to briefly mention bridges. Now that you're familiar with collision domains, you can understand how nasty it is to have lots of devices sharing the same one. Bridges were created as a way to simply divide a collision domain into smaller, more efficient collision domains by isolating the traffic. Bridges pay attention to the devices on either side of themselves and only forward data from one side to the other if it's intended for a device on that segment. Otherwise, all the other ambient traffic is ignored and you end up with increased speeds and less havoc.
The term "bridge" as described here is its original (and true) meaning, although in recent times the term has come to adopt a veritable plethora of definitions, mostly determined by marketing departments.
Switches
Simply Put...
Switches are smart hubs. They function the same way hubs do except for one major difference: They pay attention. When data is flowing into and out of a port, the switch will remember the identity of the device on the other end and will only send information to that device if it's intended for it. It basically works like you'd expect any piece of modern technology to work.
One advantage this provides over a hub is privacy since it's just about the polar opposite of the security problem discussed above. If data comes into a switch from port 1 destined for the device out port 8, the switch will obviously only send the data out port 8. This means it's just that much more private and secure, which is a good thing.
For the Nerds
Switches deal with collision domains in a much more reasonable fashion. Instead of having all the devices bumping into each other like in a hub, a switch turns each port into its own collision domain which drastically reduces the occurrence of collisions, almost to the point of non-existence. For this same reason, the speed ratings you see on switches are a little more reasonable considering that you now get, say, 10 mbps per-port instead of per-device.
It's worth mentioning that switches operate primarily on MAC addresses, which are easily spoofable and exploitable. The increased security mentioned above suffers from this to a certain extent, mostly due to ARP Poisoning, so it would benefit you to know about it. Don't get all paranoid, though, because 99.999% of the time you have nothing to worry about.
Routers
Simply Put...
Computers communicate in relatively small groups and can only talk to other computers in their same group, which is a problem. Routers solve this problem by allowing computers in Group A to communicate with computers in Group B. That's all a router does. It joins groups -- or networks -- of computers together and routes information between them.
The only reason routers are a particularly confusing subject is because in the home market you never see a true router, you always see a router/switch hybrid. In its basest and simplest form, a router only needs two ports: One for each network it's connecting to. However, this would be a pretty major inconvenience for the regular consumer since it means they would also have to buy a switch or hub in order to connect all their computers together. So, out of the kindness of their hearts, the manufacturers have decided to cram switches into home routers, which results in what you see on store shelves today. Enterprise-level routers (like the ones the internet runs on) look pretty much nothing like home routers.
It's also worth mentioning that home routers make pretty effective hardware firewalls since they separate your local network of computers from the rest of the dangerous internet. With intelligent usage along with the standard anti-virus/anti-spyware programs, you should have no need for a software firewall if you have a router.
For the Nerds
In the previous section I mentioned a simplistic scenario in which Group A (from here on I will use the word Subnet instead of Group) needs to communicate with Subnet B, and a router would be the device to facilitate this communication. Now imagine you need computers in Subnet A to communicate with computers in Subnet L by going through Subnets B, C, E, and H. It gets exponentially more complicated as the network gets progressively complex, so routing protocols were created to handle it. Routers use routing protocols to communicate with neighboring routers, advertising the networks they are connected to. For example, a router would announce that it was connected to Subnets F and G, and if another router on the opposite side of the network had to send a packet to Subnet G, it would know where to send it thanks to this update. As a network gets larger and more redundant, multiple paths to the same subnet open up so the router would then use the information provided by the routing protocol to calculate a best path to that subnet using various algorithms.
It gets pretty complicated from here and we're getting outside of the scope of the article. If you want to get in-depth with routers, pick up a couple cheap ones off of eBay and start learning about these routing protocols and figuring out how to configure them. Now that's a good time.