Biological altruism is used to describe actions creatures in nature perform that reduce their reproductive fitness – their ability to produce offspring – while improving the reproductive fitness of others. An example of this is the Vervet monkey, which, when predators approach, will give off a warning call that alerts other monkeys that danger is near, but also alert the predator to the warning monkey’s location. Giving a warning call reduces that single monkey’s reproductive fitness, indeed its very chances at survival, for the benefit of the other monkeys. According to natural selection, would not the monkeys possessing this alarm calling instinct have died out long ago, expunging the trait from the species?
This is the question posed and answered in Stanford's Encyclopedia of Philosophy article titled, "Biological Altruism." The article provides a progression of theories, critiques and defenses, and finishes the whole thing up nicely with an application of these theories towards understanding the evolution of human behavior.
The key thing to remember here is that biological altruism is measured in cost and benefit to different organisms' reproductive fitness, that is, the effects of the altruism, with little thought as to the intent of the altruist. We're discussing non-human creatures here, so intent can't play a part, given the natural assumption that most organisms do not have conscious thought and are incapable of intentional altruism.
The first theory presented to explain how altruism is able to evolve through (or despite?) natural selection suggests that natural selection occurs at a group, rather than individual, level. A group with altruists ready to sacrifice themselves for the good of the group has a greater chance of survival compared to a group full of selfish organisms who will let their fellow organisms die. Thus, natural selection would favor the altruistic group.
From Darwin's The Descent of Man (1871):
a tribe including many members who ... were always ready to give aid to each other and sacrifice themselves for the common good, would be victorious over most other tribes; and this would be natural selection. (p.166)
A major problem with this between-group theory, however, is the concept of "subversion from within," and addresses the problem of free loaders. If a group of organisms exists that is 100% altruistic, and a single organism is introduced with a mutation that caused it to be selfish rather than altruistic, that selfish organism would reap the benefits of the altruism of others, while incurring none of the costs itself. It would have a greater reproductive fitness, as would its offspring, and its offspring's offspring, and, due to the superior fitness of the selfish organisms, altruism would eventually be bred out of the group.
To reconcile this problem, the kin-selection theory was born. What if the altruist organisms discriminated between who would and would not benefit from that altruism? If altruists behaved so only towards their kin, then the inclusive reproductive fitness of creatures possessing the "altruist gene" would increase, thus increasing the chances that the gene will prevail through the generations.
Kin selection theory predicts that animals are more likely to behave altruistically towards their relatives than towards unrelated members of their species. Moreover, it predicts that the degree of altruism will be greater, the closer the relationship.