We customarily teach atoms as “wanting” to fill their valence shells with electrons, thus setting up the whole of chemistry with covalent or ionic bonds. But what’s really in it for atoms to form covalent bonds?
Turns out not to be so simple! Isolated atoms DON'T particularly tend to pick up, nor lose, free electrons; they are quite happy as neutral particles. Extra electrons would repel each other on an atom (ion), which is not energetically favorable unless the ion is stabilized somehow. And a loss of electrons would lead to a cation disposed to reacquire the electrons lost. That’s NOT evidence of “wanting to fill” the valence shell!
So, consider instead what’s in it for each of the subatomic particle types in two atoms near each other that could share electrons. First, for the nuclei, there’s no advantage in bonding! If anything, if the shared electrons didn’t completely screen out the positive charges of the two nuclei from each other, they would repel each other ferociously.
The key to the bonding is the value to the electrons. The only reasons electrons are on an atom anyway, is that they are energetically trapped there by electrostatic attraction to the nucleus. It’s a proximity effect. When they participate in a covalent bond, now they allow themselves to be electrostatically trapped by two nuclei at once. This is a deeper trapping (trapping means they have negative energy, relative to being free electrons) than what they enjoyed from one nucleus! Note that trapping is not the same as an attractive force per se: the electrons can be exactly midway between the two nuclei, so that the net electrical force on them is balanced to zero, but if they attempted to escape ‘sideways’, they would be doing it against the net vector force from the two nuclei combined, which would be more difficult than escaping from just one atom’s nuclear attraction. Incidentally, if you think of the two adjacent nuclei as "trapping" the covalent bond electrons, you are half right -- the covalent bond electrons are also "trapping" the nuclei. None of the assemblage (two nuclei and the covalent bond electrons) can move apart from each other -- they are grouped together by their mutual loss of energy as a combined system when bonded.
So, now that you appreciate the value to the electrons of being shared, why is the valence shell filled with a particular number of electrons? Why, in fact, are there these weird things called orbitals, to keep track of?
To answer that, think what “life” is like to an electron: all it can possibly know is if it’s getting a pull or a push from charged particles around it. It can’t “see” them: the wavelength of visible light is far bigger than the size of an atom. It would be as if you were trying to negotiate a crowded hallway between classes, blindfolded, at breakneck speeds. You would think there must be a better way! And so there is, for subatomic particles, and particularly electrons: they have a cooperative behavior or property, namely their distribution in orbitals, which allows them to be all present around an atom, including in overlapping space, yet able to ignore each other completely – and not go crazy repelling each other electrically. You will study about orbitals and their shapes. The thing that organizes them all into a single mental picture, is that all the orbitals have the shapes they do JUST SO THAT the electrons in them can all ignore each other. The orbital shapes are in fact the simplest way of exactly arranging this! You might wonder, why doesn’t each electron just stake out a tiny piece of space-turf, and stay there? Couldn’t all the electrons be happy just keeping to themselves, and not moving outside their little boxes? Unfortunately, electrons behave a bit like kittens (if you’ve ever tried to keep an energetic kitten in a corner, you know what I mean!) – they need to stretch out, and it takes a lot of energy to coop them up. So that kind of arrangement wouldn’t be a lowest energy state. And nature always makes use of lowest-energy arrangements!
So what makes for an orbital? Each electron has a mathematical description, termed a wavefunction. Like any other kind of function, it has various values at different points in its domain (domain = space around the nucleus), and in particular, it may have (and usually does) what we think of as “+” and “–“ values to the function. The +/- signage of the wavefunction refers to no particular physical property – though you could think of it as like positive vs. negative signs on numbers. [It's a bookkeeping notation for a basic property of electrons as waves -- you know that wave trains generally consist of something moving first one way from rest, then the other way -- but that both directions of movement are part of the wave. It's a little like that for wavefunctions, except that the wavefunction doesn't describe something moving, but simply being.] One thing it is NOT: it is not related to positive and negative electrical charges. Another thing it is NOT: it is not “good” when it is “+” and “bad” when it is “-“ – in fact, whether it is “+” or “-“ it still stands for some of the electron. In places where the wavefunction value is zero, then the electron just doesn’t hang around there.
When we picture the orbital of an electron, we look for all the places in space where the wavefunction has a particular, low value (either positive or negative) – these places will describe a surface, like the surface of a balloon, that show the outline of the orbital. Outside that surface, the wavefunction values are even smaller (closer to zero), hence the electron is very unlikely to be found there; inside the surface, where the wavefunction values are larger (farther from zero), the electron is correspondingly more likely to be found. When the orbital has more than one piece, adjacent pieces will have opposite wavefunction signs, and there is a plane or other surface (termed a “node”) between the two pieces where a single electron is never to be found – yet, it can be found to both sides, and pass freely across the plane without ever spending time ON the plane itself!
Now, the neat thing about orbitals, and the electrons in them, is the following. To electrons in two different but spatially overlapping orbitals, how do they manage to ignore each other? It turns out they take a mathematical approach to this. To see if the two electrons are going to have an electrical turf war or not, we calculate what their wavefunctions do in space with each other: for each point in space, we multiply the value (including the sign!) of the wavefunction of electron#1 by the value (including the sign!) of the wavefunction of electron#2. Then, over all of space, we add up all those wavefunction product value bits, to make a grand sum. And we find, that because (typically) one orbital only had a “+” signed shape, and the other orbital had a shape that split into “+” and “-“ parts, that the grand sum included some “+” signed product bits, and the same amount of “-“ signed product bits, for a net grand sum of zero. A net grand sum of zero means the electrons in the two orbitals are able to ignore each other, completely. On the average (over the whole atom) the two electrons’ wavefunctions are said to not “interfere” with each other.
If you think about the types of orbitals and their pieces, you see that each successive orbital type in the s, p, d, f … series adds one more plane cutting space into sections, and that each individual orbital type can therefore ignore all the others. Among orbitals of one type, but different shells (i.e. 1s, 2s) a different nodal “plane” enters the picture: it is not flat, but a spherical (or other radially organized) surface. So a 2s orbital has both an inner ball part (with a “-” wavefunction sign) and an outer shell part (with a “+“ wavefunction sign). If you think about it, you can see that such 1s and 2s orbital wavefunctions, when multiplied together, can (and do) add up to zero, given an appropriate position of the spherical “node”. Similarly for 2s and 3s orbitals (3s has two spherical nodes, one inside the other, and +/-/+ signed values to the successive layers). This all keeps all the electrons on atoms “away” from each other, even while their positions extensively overlap.
Now, what good are orbitals? They turn out to be very useful for thinking about where valence electrons might be located around the atom for forming bonds. One particular result of this is that p orbitals directed directly down an axis through two bonded nuclei(let’s call this the x axis) will form a covalent bond in which the electrons “sit” (in a cloud) centered right on the line between the two nuclei. Because these bonds are typically made with at least one s orbital (such as from an H atom), they are given the name of the Greek equivalent of s: sigma. But p orbitals directed along the other two Cartesian axes don’t appear to be heading towards the other atom, off on the x-axis. How can they form a bond? It turns out, that when they cooperate with electrons in the corresponding similar orbital on the other atom, the overlap zone (where the electrons will concentrate their time) is on the plane separating the two atoms, just NOT right on the line joining the nuclei – hence, they are symmetrically off-center between the two atoms. Even off-center, they are still in the dual-energy-well of covalently bonded atoms – in short, they form a covalent bond. Because these bonds are typically formed from at least one p orbital, they are given the name of the Greek equivalent of p: pi.