Logic inside a 3 or 4 way light switch?
A "3-way" switch is SPDT. A "4-way" switch is DPDT inside. They're used like this:
simulate this circuit – Schematic created using CircuitLab
The 4-way switch is simply crossing the connections, or connecting them straight through — sort of an XOR function.
If you only need two switches, just connect SW1 and SW2 directly to each other. If you need 3 or more switches, add any number of 4-way switches in between as shown.
Hot or not
Here is how they work; it is simplicity itself. You have 2 traveler wires. One is hot, and one is not. Any 3/4 way switch alternates which one is hot or not.
At the ends, an SPDT will do the trick.
However in the middle, you need to exchange the travelers. This is done by a reversing switch.
A reversing switch isn't quite a DPDT. But you can make one out of a DPDT by wiring an "X" connecting the non-common terminals, then attaching the wires to the one side of the "X" and of course the commons.
Mains wiring gotchas
The usual place people get into trouble with 3-ways in household wiring is failing to properly identify the travelers. These live on the 2 "traveler" or non-"common" terminals, and in North American practice are colored brass. Notably, physical position of the terminals on the switch is meaningless; every switch is different. I like to use yellow wire or mark the wires with yellow tape. Doing so makes working with 3-ways easy; failing to do so makes it a nightmare. Most homes are wired in cable, and so you get a box with a 3-way and other stuff going on, and you have 9 wires with every one being black, white or red. What a tangle!
man, I really shoulda marked those travelers with yellow tape...