The NMRA connector is a plug and socket combination used as a Locomotive Interface between the decoder and the locomotive wiring. The NMRA standard also defines the colour code that should be used for connections.
The medium size has eight pins/sockets. Many manufacturers build sockets into their locomotives, and install a dummy plug to complete the circuit. To install a decoder equipped with a plug, you remove the factory installed plug and insert the decoder's plug.
The medium plug is arranged in such a way that by plugging in a decoder incorrectly, no damage will occur, the engine just runs in reverse.
The large plug has only 4 pins and is typical for large scales like O. The small plug has 6 pins, and is meant for N scale applications.
The JST Connector is a different animal, often used to connect the harness to the decoder PCB.
21 Pin MTC Connector
NMRA also adopted a 21 pin connector intended for sound decoders. This is a direct PCB connector (there is no wiring harness), the decoder is intended to plug directly onto a fixed pin header inside the locomotive. This is known as the "MTC" connector.
The NMRA standard has discouraged the use of this connector in new locomotive designs from January 2010 but as of 2013 there are still many locomotives in production with this connector and obviously there will long be a market for compatible decoders.
Comparison with NEM Connectors
The small, medium and large NMRA connectors are directly equivalent to the NEM connector standards (NEM 651, NEM 652 and NEM 654).
The 21 pin MTC connector is equivalent to the NEM 21 pin connector (NEM 660)