Hubs are repeaters. They send every signal received at every connection to every other connection in the box. They don't operate at any particular network layer. Logically they are LAN devices of which a network consists. Received packets are sent no matter where they belong. There are new "smart" hubs that do more than this, but that's how they started.
Switches inspect the recipient/gateway MAC address of an arriving packet and send the packet out on only one wire, where that recipient is connected (based on automatic discovery of the connected devices). They operate at layer 3 of the network stack. Logically they are LAN devices of which a network consists. Received packets that are already on the correct network segment are discarded. There are new "smart" switches that do more than this, but that's how they started.
Routers inspect the recipient/gateway IP address of an arriving packet and send the packet out only one port, to another network that is closer to the recipient's network (based on routing information programmed by an administrator or dynamically exchanged between routers). They operate at layer 4 of the network stack. Logically they are WAN devices sitting between networks. Received packets that are already on the correct network (or already closer than any other route known to the router) are discarded. There are new routers that do more than this, but that's how they started.
Now there are machines that operate at layer 3 AND layer 4. My descriptions may be basic or somewhat simplified, but they are essentially accurate.
For what it's worth, a hub is electronically faster than a switch. It does not inspect packets and has no queue or CPU in it. If two computers are attached, and one sends a ton of data while the other only receives, the transit time for the hub would be faster than a comparable setup with a switch, and the throughput would be nearly identical.
It is only when network activity is initiated by many computers at once that the weakness of a hub shows up: packets start to "collide" (be sent at the same time) and must be resent. Switches and hubs do not have this problem because they sent traffic to only the intended recipient, from a FIFO queue. They have their only problem, which is that the more traffic there is and the longer the routing tables become, the higher the latency (delay) in forwarding each packet.
-------------------------------------
• Every joy is beyond all others. The fruit we are eating is always the best fruit of all.
• It is waking that understands sleep and not sleep that understands waking. There is an ignorance of evil that comes from being young: there is a darker ignorance that comes from doing it, as men by sleeping lose the k