How can Nitrogen and oxygen form nitrogen dioxide if both nitrogen and oxygen have a negative charge?

They don't. Oxygen, in the free state, (such as in air that you and I breathe) is zero charged. So is the nitrogen in the air, in the free state. In fact, ALL elements in the free state (uncombined with anything) have a zero charge and a zero oxidation state. One "valence value" of oxygen is -2 and one valence value for nitrogen is +4 and that accounts for NO2. Nitrogen is one of those animals with many different valences (I prefer to call them oxidation states) with +1, +2, +3, +4, + 5, and -3 for starters.

Nitrogen and oxygen do not have a negative charge in their neutral state. They both have an equal number of protons and electrons, resulting in a balanced charge.

To understand how nitrogen and oxygen can combine to form nitrogen dioxide (NO2), let's explore their electronic configurations.

Nitrogen has an atomic number of 7, so it has 7 electrons distributed among different energy levels. The electronic configuration of nitrogen would be 1s^2 2s^2 2p^3. Oxygen, on the other hand, has an atomic number of 8, with an electronic configuration of 1s^2 2s^2 2p^4.

When nitrogen and oxygen combine, they can share electrons through a covalent bond formation. In the case of nitrogen dioxide, one nitrogen atom (with 5 valence electrons) shares electrons with two oxygen atoms (each having 6 valence electrons).

The sharing of electrons allows the atoms to achieve a stable electron configuration by filling their outermost energy levels. Nitrogen can complete its octet by sharing one electron with each oxygen atom. This results in a double covalent bond between one nitrogen atom and each oxygen atom, like this:

O
/
N = O
\
O

In this structure, the nitrogen atom is bonded to both oxygen atoms, and each oxygen atom has a lone pair of electrons. The formal charge on each atom is balanced since the nitrogen atom gained a partial positive charge while the oxygen atoms acquired partial negative charges.

So, in summary, nitrogen and oxygen can form nitrogen dioxide (NO2) through a covalent bonding by sharing electrons, allowing them to achieve stable electron configurations.