There are two 3s electrons in Mg. You can tell this easily, by looking at the periodic table. Mg is in the third row (3) and second column (s=2.)

This trick works in the p-block as well, so if you look at Oxygen, it’s got the 2s^2 ( because it’s in the 2nd row and it has passed the 2s column), and then it’s the fourth element in on the p-block (p=4.)

So, oxygen’s noble gas configuration is [He] 2s^2 2p^4