The diagram below shows how a 2 way switch wiring works.
Image source: Circuit Digest - 2-Way Light Switch
Let's name the first switch as switch1 and second as switch. If you look closely these two switches are SPDT switches (Single Pole Double Throw),
how a SPDT switch works is - it has a main pole that can be connected to two different outputs.
In the above diagram the switch1 is connected to output 1 and switch2 is connected to output 1 then its an open circuit and the bulb will be in off state. Imagine if you toggle switch1, it now connects to output 2 which is connected to neutral, this closes the circuit, effectively turning the bulb on, now flipping the switch 2 connects the output 2 which opens the circuit and this now switches the bulb off.
This is the basic working model of a 2 way switch, for electronically controlling this we can use a SPDT relay.
Image source: What Is a Relay?
This is what a relay's diagram looks like, and if you did notice, this is exactly what a 2 way switch looks like but with an addition of a coil which is used to control the output of the relay.
You can replace the 2 way switches in the above diagram with relays, and then control the relay using an output from a microcontroller.
With the basics cleared, I hope you yourself can figure out how a 3 way switching system works.