Standard mono phone plugs have two separate electrical connections along the barrel, one at the end called the tip, for the audio signal, separated by a plastic ring from a second one called the sleeve, which is the ground reference. (The voltage difference between the signal and ground connections determines the amplitude of the audio signal.) Stereo connectors add another connector between those two, the ring; these TRS (tip-ring-sleeve) plugs by convention carry the left channel on the tip, the right channel on the ring and the ground on the sleeve.
To add a microphone signal to these you add a fourth connector in the same way, giving you a TRRS (tip-ring1-ring2-sleeve) plug: four metal rings separated by three plastic rings.
Here are examples of TRRS and TRS plugs:
(Source: Wikimedia Commons.)
There are unfortunately several different designs for TRRS, and this can cause compatibility problems.
Left and right audio output are invariably on the tip and first ring, just as with TRS jacks. But the ground can be on the second ring or on the sleeve, with the mic signal on the other one. Mic-on-sleeve (CTIA/AHJ standard) is the more common arrangement nowadays; it's used on iPhones (back when they had phone jacks) and the majority of Android phones and many computers, including MacBooks and my Lenovo T510 Thinkpad laptop. The older OMTP standard puts mic on the second ring and ground on the sleeve; this is mostly found on older devices dating from around 2010-2012, including Nokia and Sony/Ericsson phones, Samsung Chromebooks and the PlayStation Vita.
For compatibility with TRS jacks, TRRS jacks detect whether the second ring and sleeve are shorted together (i.e., both contacts are touching the continuous sleeve of a TRS connector), in which case they will do audio output only, or whether there are two separate connections there, one with a microphone on it. Simplifying somewhat, getting your mic detected involves putting a resistance between the device and the microphone: the resistor value varies but many microphones will be considered "unplugged" if just connected directly. Further, connecting the microphone connection to ground, sometimes through various levels of resistance, is also used to signal button presses on the headset for those that have one or more buttons.
That should be enough to give you some sense of how this works and understand the various compatibility problems that can arise with TRRS audio/microphone connections. If you need a few notes on connecting traditional devices (such as tape players and old computers) via TRRS, I have some here in the section "Smartphone Connections"; that also has some links to further information. If you need a deeper look at how any of the above works, the Electrical Engineering Stack Exchange is probably the place you want to ask. (What an electrical engineer would call "beginner" questions are welcomed there.)
It may also be worth noting that stereo audio + microphone is not the only purpose to which TRRS jacks have been put. I've also seen them used to carry mono or stereo audio + video, for example, and even for a computer serial data connection. So don't assume that anything with a TRRS jack is always designed for headphones or a headset.