Atoms become charged when they either gain or lose electrons. Normally, an atom has an equal number of protons (positively charged) and electrons (negatively charged), so the overall charge is neutral. When an atom loses one or more electrons, it has more protons than electrons and becomes positively charged, called a cation. Conversely, if an atom gains electrons, it has more electrons than protons and becomes negatively charged, known as an anion. This gain or loss of electrons results in an imbalance of charge, causing the atom to become charged.
Atoms balance their charges by becoming ions when they gain or lose electrons. The atom's charge balance can also involve attraction between opposite charges — the positively charged ions and negatively charged ions are attracted to each other, helping to stabilize the overall structure in compounds. In addition, atoms can share or transfer electrons through chemical bonds to achieve a stable charge balance.
In summary, atoms become charged by losing or gaining electrons, leading to an electrical imbalance. They balance these charges by forming ions, which can attract oppositely charged ions or share electrons in bonds to achieve stability.