Atoms have positive or negative charges when the number of protons (positively charged particles) and electrons (negatively charged particles) is not equal. The charge of an atom is determined by the overall balance of protons and electrons.
In a neutral atom, the number of protons in the nucleus is equal to the number of electrons orbiting around it. The positive charge of the protons cancels out the negative charge of the electrons, resulting in a net charge of zero.
However, atoms can gain or lose electrons through various processes. When an atom gains one or more electrons, it becomes negatively charged because the number of negatively charged electrons exceeds the number of positively charged protons. This type of atom is called an anion.
On the other hand, if an atom loses one or more electrons, it becomes positively charged because the number of protons now exceeds the number of electrons. This type of atom is called a cation.
It's important to note that the number of protons in an atom determines its atomic number and defines its identity as a specific element. When the number of electrons changes, the atom becomes an ion with a different overall charge but retains its identity as the same element.