The hub works in the physical layer and belongs to the 1 layer equipment. Every time data is sent, all ports can receive it. Switches work at the data link layer and belong to Layer 2 devices. Each port forms a MAC address forwarding table, which forwards data according to the MAC address of the packet instead of broadcasting.
The working principle of the hub is broadcasting. No matter which port receives the data, it must be broadcast to all ports. When there are many access devices, the network performance will be greatly affected. The switch forwards data according to the MAC address. After receiving the packet, it will check the destination MAC address of the packet and find the corresponding port to forward it instead of broadcasting it to all ports.
Hub adopts bus topology structure, and each node communicates through a bus. The sending and receiving of data packets adopt CSMA/CD protocol, which must be unidirectional and can only maintain half-duplex mode. Two ports cannot send and receive data at the same time. When two ports communicate, the other ports work differently. When two ports on a switch communicate, the channels between them are independent of each other, and full-duplex communication can be realized. Both ports send and receive data at the same time.