Mobile edge computing (MEC) is a recent communication paradigm developed mainly for cellular networks. MEC is introduced to improve the whole network efficiency by offloading its operations to nearby clouds. Cellular networks are able to offer the cloud computing capabilities at the edge of the radio access network through MEC servers. Mobiles services and tasks can either be executed at the mobile device or offloaded to the edge server. In this work, we provide a latency aware and energy aware offloading algorithm for the 5G multilevel edge computing based cellular system. The algorithm enables the mobile device to request offloading or decide the local execution independently based on the available resources at the mobile device and edge server. The algorithm takes into consideration the energy consumption to handle the service and make the offloading decision that achieves higher energy performance. The system is simulated and numerical results are included for performance evaluation. © Springer Nature Switzerland AG 2018.