This is a big question, but here's an overview of the main electric systems.
4.5V (1966 - 1986)
The original 4.5V system worked with 3 x 1.5V C cells. It was produced between 1966 and 1986 and was used to power motors and lights in a wide variety of trains, technic, basic and even DUPLO sets.
12V (1969 - 1993)
Coexisting with this system, a 12V standard for LEGO Trains was introduced in 1969 and produced until 1993. The power was supplied by DC Transformer. There is no electrical compatibility between 12V and 4.5V components, and the higher voltage can damage the lower-rated parts. In addition to motors and lights, an assortment of other 12V accessories were available such as automatic switch points. The 12V system had two wires or three wires for track switches.
9V (1985 - 2008)
9V became the LEGO standard in the early 90s. There were several different power sources, such as a single 9V battery, 6x 1.5V batteries and a DC Transformer (used exclusively for trains). The 9V system is electrically incompatible with either the 4.5V or 12V systems, but as I understand it, 9V components are electrically compatible with each other. 9V was a 2-wire system. Philo's web site provides electrical details of a variety of 9V motors.
The first generation of Mindstorms, the RCX generation, was again based on 9V. The original 1.0 version could be powered using a 10V DC transformer, but later versions took 6xAA batteries. It used standard LEGO 2-wire 9V connectors. When powered, the sensor inputs can supply power (at a bit less than 9V). More details of the electrical characteristics of these ports can be found in Claude Baumann's Making Your Own RCX Sensors. The same sensor interfaces were also used on the earlier and less well-known Lego DACTA Interface B but unlike on the RCX powered and unpowered sensors used different ports on Interface B (this is why powered and unpowered sensors were different colours).
The RC system was introduced in 2006. The RC system uses 9V components but generally includes a remote and a chunky RC brick that peripherals can connect to.
Power Functions (2007-2021)
Power Functions (PF) use a 4-wire system, the outer two wires providing power and the inner two control functions. Once again, it is nominally a 9V system, although it will cope with some variation to accommodate various types of batteries. For example, the 88000 AAA Battery Box uses 6 x AAA to supply up to about 9.6V and up to 800mA current, depending on the batteries used, whereas the 8878 Rechargeable Battery Box delivers 7.4 V at up to 1.1A (?).
Lego sold an extension/adapter cable that can be used to supply old 9V devices from a power functions source. It can also be used to supply ordinary power functions motors from an old 9V source but not to supply power functions IR receivers or server motors. See Does the LEGO "Power Functions Extension Wire" (8886) work in both directions between old 9V and new Power Functions devices? for more details.
Mindstorms NXT and EV3 (2006 - 2021)
The Mindstorms NXT system is a 6-wire system. Two wires retained the 9V motor and sensor systems from the RCX while the other four provided tachometer functionality on the motor ports and a digital sensor interface on the sensor ports. This system was available from 2006 to 2013.
The Mindstorms EV3 uses the same 6-wire connectors as the NXT but additional functionality and an auto-detect system were added. Unfortunately in doing this, they broke compatibility with 2-wire devices. EV3 was available from 2013 to 2021.
Lego sold an adapter cable for going from the NXT to the old 9V connector. This allowed old 9V motors and RCX sensors to be used with the NXT. It also allowed NXT motors to be powered from a 9V source (obviously losing the tachometer functionality) and the NXT touch sensor to be used with RCX or Interface B. Unfortunately, this cable doesn't work correctly with the EV3.
Powered Up (2016 - Present)
Begining in 2016, products across all product lines began using the same electrical standard. This change began with WeDo 2.0 and eventually grew to include Trains, Technic, and Mindstorms.
This system goes by many names, including Powered Up, Control+, LPF2, WeDo 2.0, BOOST, and Robot Inventor. Hubs and peripherals from these systems are generally compatible with one another.
This system includes hubs that can be controlled via Bluetooth, allowing apps to control most sets.
Electrically, this system is still 9 volts, but the connector and signalling are not compatible with any of the previous 9v systems. An adapter has never been produced to connect this system with older components.