Let’s take a look at the simple network.

It has users, two switches and a server. As long as all links to the switches are working, users can transfer information to the server. But as soon as at least one link is down, users will also disconnect from the server. Let's start correcting this situation. Let's take into account that the most dangerous place is between two switches. After all, if the link to one of the users is disconnected, only he is disconnected, and if the connection to one server is disconnected, then only this server is disconnected. And if the connection between the switches goes down, all users will lose communication with all servers.

If we just add another link between two not-so-smart switches, then they will start flooding each other due to the resulting network loop. The network will then stop working. Why it happens? This is due to how the switch works. When it receives a network packet whose destination address it has not learned, switch sends it to all of its ports, except for the one from which it received the packet. Due to the fact that two switches have two links between each other, they will start sending this packet to each other endlessly, taking all their resources for forwarding it. I would like to draw your attention to the fact that a "loop" can occur not only between two switches (as shown in the figure), there can be more switches that form a loop (or ring). The more there are, the more difficult it is to find the cause of the problems.
Fortunately, there is a wonderful family of Spanning Tree Protocol (STP). They are used by more advanced switch models to determine how switches are connected to each other. And they turn off unnecessary links as long as the main ones work.

When a new link appears on a switch with STP enabled, the switch first tries to "talk" with the device it was connected to. If the second device also supports STP, then they determine the status of this link among themselves. If it is the only one up to the root switch, or it is on the shortest path to it, then it is activated. Otherwise, the switches do not send user traffic over it as long as there is a shorter route to the root switch.
Note that we have connected the two switches with two links, but we use only one of them at the moment. Not very effective, isn’t it? At the STP level, we can correct this situation a little. Classic STP and its faster edition, Rapid Spanning Tree Protocol (RSTP), consider all links between switches in terms of physical links. If the path turns out to be not optimal, then the interface is completely unused, as if a cable was pulled out of it. But there is the wonderful Multiple Spanning Tree Protocol (MSTP). It is able to make a network without "loops" for each and every VLAN separately. At the same time, different VLANs can use different links as active and blocked. That is, in our example, we could configure the switches so that some users use the upper link as the main one, and some of them use the lower one. And after the break of one of them - they would be combined in one link.
For similar purposes, you can use another technology - Link Aggregation Control Protocol (LACP). It allows not to separate links for different VLANs, but provides automatic selection of one of the available links between switches for each incoming packet.

With a sufficiently large number of users, LACP is able to more or less evenly load all available links between switches (there can be up to 8 of them). To select the interface on which traffic will be sent, the switch calculates a hash value that shows the number of the physical interface within the virtual aggregated interface. The hash function can be calculated based on the MAC and IP address of the source and destination and some other data. The specific option is selected during configuration.
This protocol not only allows you to use several physical links between two switches at the same time, but also automatically adapts when the number of these links changes, that is, if one of the links is down, the connection between the switches will not be lost.
But what if we want to make redundancy not only for communication lines, but also for switches?

By adding a second switch on the right side, we lost the ability to use LACP, because it can only work between two devices (end to end), and we now have three. In this case, we are again forced to use STP, which turns off the traffic going through one of the switches. MSTP can help you to use different connections for different VLANs, but it's still not as convenient as LACP.
If you want LACP across multiple switches, then that's possible. Meet: Multichassis Link Aggregation Group (M-LAG)!

If we use M-LAG, we can combine the two right switches into one virtual switch, but not completely, but only for the vision of the left switch. That is, switch 1 will think that it has two links to the same switch 2, but in reality these will be links to the two different physical switches.
Using a dedicated link between each other, the two switches on the right agree to act as one virtual switch. They configure one common aggregate interface that connects to the aggregated interface on the left switch using LACP. The left switch doesn't care now that there are two switches on the right, for him it is one. But the right switches need to do additional work. After all, it can happen that the traffic that came to the upper switch must then be sent through the lower one (or vice versa). In this case, they use a special connection between themselves to transmit such "missed" packets.
Want more? Let's make two parallel switches on the left too.
They can also be configured with M-LAG or stack. In this case, the left switches will think that they have cheated one right switch by posing as one virtual switch, and the two right switches will think that they have cheated the left switch.
