It's recommended not to mix capacities and speeds
Install memory in an iMac - Apple Support
For optimal memory performance, DIMMs should be the same capacity, speed, and vendor. Use Small Outline Dual Inline Memory Modules (SO-DIMM) that meet all of these criteria:
- PC4-21333
- Unbuffered
- Nonparity
- 260-pin
- 2666MHz DDR4 SDRAM
If you have mixed capacity DIMMs, see the
install memory section for installation recommendations.
My recommendation would be to just use the 2 16 GB modules. as an extra 8 GB rarely will make much difference.
But you can try and see, as long as you follow the guidelines it should still work.
You can always just remove the 2 4GB modules if it misbehaves.
Good luck!