system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why do "bad" smells smell bad, and "good" smells smell good?

Are "bad" and "good" smells learned or influenced, or are they just simply good and bad?
gpt
It's a little bit learned and a little bit encoded by evolution.  For instance, poop has a lot of bacteria in it and other nasty things that you don't need to be around.  Evolution favored animals that stayed away from their poop (generally speaking), so poop smells bad so you won't go near it, so you won't get sick.  Likewise, rotting meat smells bad because you really shouldn't be eating it, so again it smells bad so you stay away from it.  Often what you're smelling is sulfate compounds, which commonly occur where there's decomposition by anaerobic bacteria.  Sulfur smells pretty bad on its own, and it can be poisonous, and when you add oxygen (the -ate in sulfate) it just gets worse.

Fun fact, garlic gets its smell from selenium, the next element in the same column as sulfur.  That whole column smells bad, except for oxygen.  Given how poisonous oxygen can be, it *should* smell bad, and the only reason it doesn't is because 1) you're constantly inhaling it and 2) you need it to live.

Similarly, many good smells, like cooking food, smells good because it's something you should be around.  Cooked food has more available calories and nutrients and is less likely to get you sick than raw meat.  Cleanliness and freshness smells good because being clean helps you avoid disease.  Evolution favored many of those smells.

But smell is also *very* strongly associated with memory in your brain.  So you're also likely to pick up some scents as being good or bad because of the memories associated with those smells.  That's why after a bad case of food poisoning, the smell of whatever food got you sick will make you nauseous - you've associated the smell with feeling awful.  That's a great trick to keep you healthy, of course - early humans would have learned very quickly to avoid the foods that were more likely to kill them.  Good memories can make smells seem more pleasant, too.  So there's a bit of both in there.

Also worth noting, what smells good or bad depends on your species, too.  Turkey vultures are one of the few birds that finds food with smell, and they eat rotting flesh.  So to them, the smell of dead things probably smells very good.