How come d 2 in nitrogen and 6 in oxygen

The numbers 2 and 6 correspond to the number of electrons in the outermost energy level of the nitrogen and oxygen atoms, respectively. These outermost energy levels, also called valence shells, are involved in chemical bonding and determine the chemical properties of the elements. Nitrogen has 5 electrons in its outermost energy level and needs to gain 3 more to fill its valence shell, while oxygen has 6 electrons in its outermost energy level and needs to gain 2 more to fill its valence shell. These elements can either gain electrons to form negatively charged ions, such as N3- or O2-, or share electrons with other atoms to form covalent bonds and molecules, such as nitrogen gas (N2) or oxygen gas (O2).