As @Icrmorin said the naming conventions may vary but for the examples you gave, ResNet and DenseNet, the numbers in the name correspond to the number of layers:
Table 1 in the Densenet paper provides an overview:
As you can see, for example, in the DenseNet-121 column this network has $1+6*2+1+12*2+1+24*2+1+16*2 + 1 = 121$ layers and that is where the name is derived from.
The ResNet paper provides a similar overview:
Again, you can see how the names are derived: for example ResNet-18 has $1+2*2+2*2+2*2+2*2+1=18$ layers.
Note that in both papers only conv. and dense layers are counted but not the pooling layers.