The designer of a cementless hip stem in total hip replacement must find a balance between two conflicting demands. On the one hand, a stiff stem shields the surrounding bone from mechanical loading (stress shielding), which may lead to bone loss, particularly around the proximal part of the stem. Reducing the stem stiffness decreases the amount of stress shielding and hence the amount of bone loss. However, this measure inevitably promotes higher proximal interface stresses and thereby increases the risk of proximal interface failure. The designer's task therefore is to optimize the stem stiffness in order to find the best compromise in the conflict. Yet, a better compromise might be found when the stem material was nonhomogeneous, in other words when an arbitrary distribution of the elastic properties inside the stem was allowed. The number of conceivable designs would increase enormously, making the designer's task almost impossible. In the present paper, we develop a numerical design optimization method to determine the optimal stiffness characteristics for a hip stem. A finite element program is coupled with a numerical optimization method, thus producing a design optimization scheme. The scheme minimizes the probability for interface failure while limiting the amount of bone loss, by adapting the parameters describing the nonhomogeneous elastic modulus distribution. As an example, a simplified model of a hip stem is made, whose modulus distribution is optimized. Assuming equal long-term bone loss, the maximum interface stress can be reduced by over 50 percent when compared to a homogeneous flexible stem, thus demonstrating the value of the new approach.