The context: the other day I was reading an article about a peculiar species of ant that when threatened by a predator would “explode” in order to help protect the rest of the colony, although it kills the individual ant. I was wondering how this kind of behavior could evolve via natural selection if it only picks out the individual organisms best suited for the environment - because it seems like a self-destruct type of behavior wouldn’t be helpful to the ants that are trying to survive and reproduce. Though it would make sense if natural selection also applies to entire populations as it does to individual organisms - picking out entire populations that are best suited for the environment. It would make sense because populations that have individuals willing to explode to help protect the other individuals would have an advantage over the ones that don’t.
The question: does natural selection apply to entire populations as it does to individual organisms or have I made a mistake somewhere in my logic - and if so, where?