if an atom is given to us, for ex: Mg then how do we find its no of electrons?
Number of protons = Atomic number
Number of electrons = Atomic number minus the charge (if it is ion)
Number of neutrons = Mass number minus Atomic number
The number of electrons in an element can change. For a neutral atom (net charge of zero), the number of protons is exactly equal to the number of electrons. So the number of electrons is also the same as the atomic number.
However, it is possible to remove electrons and not change the identity of an element. These are called ions. The charge on the ion tells you the number of electrons -- the number of electrons is the atomic number minus the charge on the ion if it's an ion. If the charge is positive, subtract that number from the atomic number to get the number of electrons (with a positively charged ion, you will then have less electrons than protons).
If the charge is negative, subtract the charge (but note you are subtracting a negative number, which is the same as adding the magnitude of the charge to the atomic number (with a negatively charged ion, you with then have more electrons than protons).
We hope that clarifies your query.