Atoms have valence shells, orbitals that layer themselves over the proton and neutron core that do (or don’t) contain electrons. An atom with the exact same number of protons in the core as electrons distributed among its “shells” has a charge of 0.
These “shells” will be there regardless of whether or not there’s enough protons to justify them. So, atoms can get additional electrons filling these outer shells _beyond_ the number of protons, giving the whole atom a -1 or -2 or so on charge. Similarly, these shells can be empty, more so than the proton count would likely indicate, giving the atom a +1 or +2 or so on charge.
Trends in this and some of the reasoning behind why this can be stable/unstable and so on is a bit more of an advanced area, but an important note is that these shells essentially form layers, that are the rows of the periodic table. A layer with only one or two electrons (or missing only one or two) tends to favor either completely filling its shell (even if it’s unbalanced), or getting rid of the fringe electrons forming a new layer. These two opposite ends pair together well, and make up a lot of salts. E.g., Na+CL-, which separate in solution and remain fairly stable, but can also form a solid without ever forming a true bond.
Latest Answers