In the story of R' Ashi and Mar Zutra, R' Ashi sacrificed his life to save Mar Zutra by feeding him from some of the kings food. The Rabbonon asked R' Ashi why he sacrificed his life and relied on a miracle to be saved, he should not have put himself into a severe sakana to save Mar Zutra from a minor sakana (maharsha). The gemara answers that "he saw tzara'as on him" - one could interpret that he wasn't relying on a miracle since he saw that there were signs of tzara'as on the meat. However, Rashi implies that R' Ashi's answer was that he saw signs of tzara'as on Mar Zutra, therefore the sakana of Mar Zutra was actually more severe, therefore he was willing to give up his own life to save the life of Mar Zutra.
The Chasam Sofer proves from this dialogue that one is obligated to risk their life to save another. Although this gemara doesn't prove any obligation, and (even if we learn like rashi and maharsha) would only prove that one is allowed to risk their life to save another; the Chasam Sofer seems to hold that when it comes to life, there can't be a choice, it is either a chiyuv to sacrifice his own life or an issur to sacrifice his own.
The Chasam Sofer challenges this premise from a Teshuva in Radvaz who seems to indicate that it would be "chasidus shel sh'tus" to sacrifice his own limb to save the life of another. However, the Chasam Sofer elaborates and says that if there is a situation of objective o'nes one is obligated to sacrifice their life and certainly a limb, to save the life of another. However, in the case of the Radvaz a goy was threatening Reuven that he should sacrifice a limb, otherwise the goy would kill Shimon. One is not obligated to sacrifice his limb to prevent the goy from carrying out his death threat to Shimon, even though Reuven's limbs is less valuable than Shimon's life. Just as we find that one is obligated to sacrifice a limb to prevent chilul shabbos, so shabbos is more valuable than a limb; if one is threatened by a jew "if you don't cut off your arm (on friday), i will be mechalel shabbos", one is not requred to sacrifice his limb to prevent the threat from being carried out.