The maximum number of layers is determined by the type of device that you have. Further, as the number of pixels (resolution) of the canvas increases, the maximum number of layers decreases. Also note that the more layers that an image has the more storage space it will consume.
When you are running out of layers or are concerned about the amount of storage space you have it is possible to (1) merge layers, which means to combine two layers into one. It is possible to undo a layer merge but once you have left the canvas screen it is not possible to return it to the state before the merge.
When merging layers it is important to remember that you need to merge from the bottom layer. Where you have (from bottom to top) layers 1, 2, 3 and wish to merge all layers if you merge layers 3 and 2 first the result may not appear correct. This is due to characteristics of the blend mode. It is necessary to first merge layers 2 and 1, and then merge the result of that with 3.