Ethernet Switch, how does it work?
OSI Model
If you aren’t familiar with OSI model, I suggest to read https://en.wikipedia.org/wiki/OSI_model
Switches are layer 2 nodes
Ethernet switches operate at OSI layer 2, an ethernet switch keeps a Look-up table that contains an entry (L2 or MAC addresses) associated with an output (Output physical port), each frame with its destination L2 address is then switched to the corresponding port.
As the switch is receiving frames, it checks whether the L2 source address of the frame already exists in the Look-up table, if the L2 source address of the frame is not in the table, the switch adds it inside, with the corresponding port from where the frame was received.
In order to switch the frames correctly, an ethernet switch read L2 header data of each frame, to be precise, it only reads L2 destination address, it then resolves the output Port by looking up the table with the L2 destination address.
What about hubs…
Hubs simply repeats received signal on all other ports, hubs are thus layer 1 nodes.