Narrowband-Internet of Things (NB-IoT) displays high-quality connectivity underpinned by fifth-generation (5G) networks to cover a wide array of IoT applications. The devices’ development and integration into different smart systems require permanent control, supervision, and the study of power consumption models to determine the performance of the network topology and allow for the measurement of the efficiency of the network topology’s application. This paper reports on an architecture and open-sourced simulation that was developed to study NB-IoT in Device-to-Device (D2D) mode, which includes the Physical (PHY), network, and application layers, as well as a queuing model, the model for uplink and downlink delays, the throughput, the overall NB-IoT D2D network performance, and the energy consumption based on the Low Energy Adaptive Clustering Hierarchy (LEACH) protocol. Our results prove that the suggested framework contributes to a reduction in power consumption, a minimization of queuing delays, a decrease in communication cost, a reduction in inter-cluster collisions, and the prevention of attacks from malicious nodes. Consequently, the framework manages the battery’s State of Charge (SOC), improves the battery’s State of Health (SOH), and maximizes the whole network lifetime. The proposed framework, the code of which has been open-sourced, can be effectively used for scientific research and development purposes to evaluate different parameters and improve the planning of NB-IoT networks.