Khazad-dûm is said the be the largest of the Dwarven kingdoms. In terms of scale how large was it? 40 miles end to end but how many levels?
Is there a way to compare it to a modern day city in terms of total size and population at its peak?
Being described as a vast Kingdom, Moria's greatness was unimaginable to many dwarves, even those of other mountain kindreds.
“The Mines of Moria were vast and intricate beyond the imagination of Gimli, Glóin’s son, dwarf of the mountain-race though he was.”
The Fellowship of the Ring: Book Two - Chapter 4, A Journey in the Dark
The fellowship find themselves under Celebdil, however as Gandalf says, the real prize of Moria is found in the deeps under Caradhras
“The lodes lead away north towards Caradhras, and down to darkness. The Dwarves tell no tale; but even as mithril was the foundation of their wealth, so also it was their destruction: they delved too greedily and too deep”
Reminding us that the Dwarves had indeed dug deep. Deep enough to awaken a very old evil that was trying to hide until its Master returned.
It's generally accepted that the Moria was built in two parts. The city towards the East, near the bridge and the 7 levels. This is where the great halls were and it's structure was likely very different to the rest of Moria. Having been built in 7 levels and 7 deeps. The image below gives us an idea of the height of the 7 levels and the location of the first deep. Considering the 7 levels cover about a mile of space, each level is likely around 700 feet high, leaving around ~50 feet between levels. Although most halls were likely much smaller than this height, one can imagine the immense size of the halls.
The depths of the deeps is unknown, but they didn't stretch past the abyss. They were likely of similar size to the levels and one could predict it to be around a mile deep.
The depth of the mines has been addressed in this answer here, and although it doesn't come up with much evidence, it gives a pretty good picture of just how deep it may go.
Now we have the length, as you say it's about 40 miles from East to West, however we have not established its width. We know that it is situated under the three peaks; Caradhras, Celebdil and Fanuidhol. This means it must be reasonably wide. Just how wide is not canonically known, statistically, but is slightly more obvious in Karen Wynn Fonstad's Atlas for Middle-earth.
From her map she suggests it's around 40 miles from Celebdil to Caradhras and another 20 from Caradhras to Fanuidhol. This seems to agree with the the time it took for them to travel from the Redhorn Pass to the Gate, and seems reasonable for Mountain ranges. Now if we look at the next image from Karen's maps, we can get a measure of the height of the Mines.
Please note this map has a vertical exaggeration of 7:1. This means that its real horizontal:vertical ratio is 7 times larger. This means the vertical height according to this is about 3 miles to the Guardroom. However the guardroom had a well go down from which drums were heard. Let's say we approximate it to be around 4 miles high in total, from Durin's Tower down to the bottom of the well.
So we've got this shape that's about 40 miles wide, ~40 miles long, and has a little bit sticking out (Fanuidhol), like an L-shape. It's around 3 miles high at Celebdil, with Caradhras and Fanuidhol likely a little smaller.
With that size, lets look at real world cities that are big. If we assume a triangle, we get a area of around 450 square miles, which equates to 1170 sq km. From here we see this is about the same size as Cincinnati, Montreal and Sydney, and around 13 times the size of Manhattan. However this is the mines in total.
If we consider just the city, it is likely no more than 2 miles long, and maybe a couple wide. Lets assume the city space occupies a square of size 2x2miles long. Taken into account the 7 levels and 7 deeps we get an area of about 56 sq miles. This is about 1.5x Manhattan, although this is counting each level as a separate space, without any "high-rise" buildings. Whether Moria has sub-levels and "floors" within levels is unknown
Above the gates
The following pieces of evidence from Lord of the Rings have bearing on this.
Firstly, Gandalf's comment on the location of the Chamber of Mazarbul from the Bridge of Khazad Dum:
I now know where we are. This must be, as Gimli says, the Chamber of Mazarbul; and the hall must be the twenty-first of the North-end. Therefore we should leave by the eastern arch of the hall, and bear right and south, and go downwards. The Twenty-first Hall should be on the Seventh Level, that is six above the level of the Gates.
In the previous chapter (Journey in the Dark) this is noted (by Gandalf again) to be quite high in the Mines:
There used to be great windows on the mountain-side, and shafts leading out to the light in the upper reaches of the Mines ... I was right, you see. We are high up on the east side of Moria.
Therefore from the level of the gates to close to the top is Seven Levels. The actual top level is likely no more than 10 to 15 above the gates (this being conjecture, and noting that levels need not be stacked tightly on each other).
Below the gates
We know for certain that there is at least one level below the gates, again from Gandalf's words:
But I know now where we are: we have reached the First Deep, the level immediately below the Gates.
The name "First Deep" alone suggests that there is at least also a "Second Deep", probably more; Gandalf also makes a comment about "the lower levels" in this same chapter, agreeing with this possibility.
That is all the evidence we have; we should note that during Gandalf's fight with the Balrog he went to "dark tunnels. They were not made by Durin's folk, Gimli son of Gloin. Far, far below the deepest delving of the Dwarves", so there are accessible tunnels below the levels made by the Dwarves but we don't have any further information on them.
So to summarize: