Mary- That's a really important and deep question. I've borrowed part of our answer to a related question, because this one is important enough to answer more than once.
Naturally, one would think that because protons are positively charged, and electrons are negatively charged, the two should attract and stick together. The reason that doesn't happen can't even begin to be explained using classical physics. This was one of the key mysteries that were cleared up right away by the invention of quantum mechanics around 1925.
The picture you often see of electrons as small objects circling a nucleus in well defined "orbits" is actually quite wrong. As we now understand it, the electrons aren't really at any one place at any time at all. Instead they exist as a sort of cloud. The cloud can compress to a very small space briefly if you probe it in the right way, but before that it really acts like a spread-out cloud.
The weird thing about that cloud is that its spread in space is related to the spread of possible momenta (or velocities) of the electron. So here's the key point, which we won't pretend to explain here. The more squashed in the cloud gets, the more spread out the range of momenta has to get. That's called Heisenberg's uncertainty principle. It could quit moving if it spread out more, but that would mean not being as near the nucleus, and having higher potential energy. Big momenta mean big kinetic energies. So the cloud can lower its potential energy by squishing in closer to the nucleus, but when it squishes in too far its kinetic energy goes up more than its potential energy goes down. So it settles at a happy medium, with the lowest possible energy, and that gives the cloud and thus the atom its size.
That basically answers your question, although we admit that the answer sounds strange. There really are very definite mathematical descriptions to go along with those words.
One fine point -- a small bit of the electron clouds actually extend inside the protons and neutrons of their atoms. The lucky thing for us is that the electrons and protons (and neutrons) do not interact in a way that changes them, in most atoms. The force of electrical attraction does not change the electrons, protons, or neutrons' identities and an electron may pass through a nucleus.
Some nuclei however, with an excess of protons and not enough neutrons to be perfectly stable, will capture one of the inner electrons turning one of the protons into a neutron and ejecting an electron neutrino. This process involves the weak nuclear force. The process must be energetically favored -- the energy of the resulting nucleus must be lower than that of the original one, which keeps it from happening over and over until all the protons are gone. The protons and neutrons obey the Pauli exclusion principle separately and fill up definite energy levels inside the nucleus. If there are too many protons, one can turn into a neutron by capturing an electron and emitting a neutrino, and drop down to a lower energy level. If you have more neutrons, then turning a proton into a neutron means it has to climb to a higher energy level, and conservation of energy keeps the reaction from happening.
A neutron is just a tiny bit heavier than a proton. If it were the other way around, Hydrogen atoms would be unstable under electron capture, and neutrons would never decay and the Universe would be a very very different place.
By the way, you raise another point, about electrons only being in particular orbits and energy levels. People (and textbooks) often say things like that. There was a brief first attempt (by Bohr) at describing atoms that way, which was abandoned when real quantum mechanics was developed. It's not just that there aren't real orbits. It's also not true that an electron has to be in just one of the states with definite energy. It can be partly in each of several, just as it can be partly in various places, and partly going various directions.
Mike W. (and Tom)
(published on 10/22/2007)