Wireless Body Area Network (WBAN) is a relatively new form of wireless networking technology that has found many potential uses, particularly in the medical field, thanks to its ability to give users a sense of independence even when they are being closely monitored. Using tiny, low-power, battery-operated biosensors, WBAN is able to monitor and report on a wide range of physical characteristics of the person being studied. The difficulty in replacing or charging batteries during experiments is compounded by the fact that these sensors are implanted on or in the body being studied. Consequently, WBAN requires algorithms that can conserve energy. Since most of the energy consumed in such networks is due to communication and data transmission among the sensors, therefore routing algorithms aiming of energy conservation are required for WBAN. This paper proposes an optimal routing algorithm which optimizes the energy consumption of WBAN. The proposed routing algorithm focuses on two methodologies. First, the optimal distancing of forwarding node from both the sender node and the receiving node, and second, fragmentation of the whole network into sets with restriction based on a known threshold length till which single-hop data transmission without any data loss is possible. The proposed routing algorithm is simulated and analyzed compared to LEACH routing algorithm which uses the method of clustering in WBAN. The proposed routing algorithm outperforms in optimizing the energy consumption of WBAN and hence increasing the network lifetime.