Often, when matter decomposes (such as a rotting carcass), a nasty smell is emitted. After speaking to my teacher, it was likely due to the nitrogen compounds that leads to the bad smell. Is this so? Why then, do nitrogen compounds smell bad to us humans?
Since this question has no answer, I thought of taking a stab at it.
Why does decomposing matter emit a bad smell?
Due to cadaverine and putrescine. More information here: What produces the strong odor of decaying dead animals?
Why do they smell so bad? Why do we perceive those smell as bad?
Let's start from the basics. Stuffs smell because they release chemicals odorants. They are volatile and hydrophobic. Different odorants have different smell due to presence of specific functional groups. Thiols smell like garlic/rotten eggs, , nitro groups gives a sweet ethereal smell. More information here: How does the smell of a compound come about, and is it possible to define a smell?
Cadaverine and putrescine has two amine groups which gives off that rotten fish mixed with that characteristic decay smell. This compound now binds with receptor proteins present in cilia. This chemical stimulus binds initiates an electric signal in the neuron, which transmits the information to the olfactory nerve, which carries the signal to the olfactory bulb in the brain and the brain processes the signal. The olfactory bulb is part of the limbic system, which is also associated with emotions. A person recognizes the odor and give off the emotion of "disgust" as a reflex action.
Recent studiesref also found that smell of death is somehow related with threat management mechanisms. The paper suggest that humans can identify threats via chemosignals. For instance, when people are exposed to fearful experience, they show a heightened startle reflex. This transmission of threat-arousing chemosignals is assumed to serve an adaptive function by orienting us to impending dangers. Cadaverine and putrescine are found to be chemosignals. The paper explains it more properly:
The decay of tissue can function as a "necromone" cue that signals an animal’s death to conspecifics. Alarm and avoidance behaviors (necrophobic behaviors) in response to these scents are widespread in the animal kingdom and thought to have evolved at least 420 million years ago. In fact, recent research shows that necrophobic behavior may have innate underpinnings through the activation of trace amine-associated receptors (TAARs), a group of specialized scent receptors in the olfactory epithelium. TAARs are known to detect specific chemicals that evoke behavioral responses, without the need for prior exposure to the scents. Certain TAARs respond to diamines (e.g., putrescine) by producing avoidant behaviors that likely serve to defend against immediate dangers . Thus, it is feasible that we have a chemosensory sensitivity to diamines like putrescine, given that their detection can aid survival.
ref: Wisman, A., & Shrira, I. (2015). The smell of death: evidence that putrescine elicits threat management mechanisms. Frontiers in psychology, 6, 1274. https://doi.org/10.3389/fpsyg.2015.01274