An ionic crystal repeats an arrangement of ions in three dimensions. A unit cell describes that repetition, whereas a formula unit describes composition. The two accounting devices answer different questions. Coulomb's law is not restricted to an arbitrarily drawn line connecting one cation to one anion: every ion contributes to the electric field experienced by the others.
The rock salt structure of ordinary sodium chloride has a coordination number of six for each kind of ion: six nearest neighbours of the opposite sign surround each ion along three perpendicular directions. Its conventional cubic unit cell contains four formula units; sharing corner, face, and edge sites between adjacent cells must be included in that count. Sixfold local coordination is compatible with overall stoichiometry.[ref]
The checkerboard plane in the diagram is a slice through this three-dimensional arrangement. It leaves out the two nearest neighbours above and below the plane. Repeating a complete even-by-even patch gives equal numbers of signs; the displayed odd-by-odd crop has a boundary imbalance and is not a complete neutral ionic crystal or a unit cell. Other salts need not have the rock salt structure or the same coordination number.
In this structural use, the coordination number counts nearest neighbouring constituents. State which neighbours are counted and which ionic crystal structure is being described; it is not an ion's electric charge number.
Eight nearest neighbours at cube corners around a central site; fluorite structure cations have this arrangement.