A sensor network consists of a set of battery-powered nodes, which collaborate to perform, sensing tasks in a given environment. Globally unique ID allocation is usually not applicable in a sensor network due to the massive production of cheap sensor nodes, the limited bandwidth, and the size of the payload. However, globally unique IDs are still necessary for nodes to implement communications to save energy consumption. Already several solutions have been proposed for supporting globally unique ID assignment in sensor networks. However, they bring much communication overhead, and they are complex to implement. We present a layer-based algorithm to solve the unique ID assignment problem. This algorithm can start by building layer-based groups to assign IDs. This algorithm, leads to save energy consumption by reducing communication overhead due to these well-organized layer-based groups. The results demonstrate that a high percentage of nodes (more than 99%) are assigned globally unique IDs with 25% efficient energy consumption, than, the reactive ID assignment scheme.