UPDATE 3: Once more building off of @Remellion's newest matrix for 42 in a legal position, here's 68 in an illegal position.
[FEN "1NQrQN2/1NP1PN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1NQ1QN2/1N1K1N2 w - - 0 1"]
Is this optimal for an illegal position?
UPDATE 2: Building off of @Remellion's impressive position for 40 in a legal position, here's a new bar for an illegal position of 66. Credit goes to @Remellion of course for making the original position that I have modified. (Although I did show the basic mechanism of it first....)
[FEN "8/NNNNNNNN/1QQQQQQQ/K6r/1QQQQQQQ/NNNNNNNN/8/8 w - - 0 1"]
Is it possible to do any more than this? Due to how crowded the position is, I think not. Could anybody provided mathematical proof that 66 is optimal? Feel free to edit it into my answer if you want to.
UPDATE: Actually, in a legal position, I have gone far past 21! I have reached 37 through capture, blocking, or moving the king. All 8 pawns have been promoted. This uses the same mechanism as my illegal position, which I made first.
[FEN "8/2NNN2B/1RQQQ3/1q4K1/1BRQQ3/2NNN3/8/k7 w - - 0 1"]
My personal best for an illegal position is 55, through capture, blocking, or moving the king. I managed to create this wild setting.
[FEN "8/NNNNNNNB/QQQQQQ2/Qr4K1/QQQQQQ2/NNNNNNNB/8/8 w - - 0 1"]
Most of the count for both positions come from the blocking moves.
OUTDATED; Indeed, 21 is more than likely the most possible if you want a legal position. I'm not sure if you want it to be a legal position, so I made it so. All 8 pawns have been promoted.
[FEN "8/Q2R2Q1/2N1N3/1N3K2/Q2n3Q/1N6/2N1N3/BkbR2Q1 w KQkq - 0 1"]
If you don't mind it being an illegal position, you can add in one more knight for a total of 22. This is iIlegal because the Black knight has no square that it could have come from, and White has one more promoted piece of than legally possible.
[FEN "3R4/Q5Q1/2N1N3/1N3K2/Q2n3Q/1N3N2/2N1N3/BknR2Q1 w KQkq - 0 1"]