I always tell my students that they should never just write down an equation blindly and start plugging things in. If you don’t understand what you’re doing, you’re much more likely to make a mistake.
Sometimes I don’t take my own advice. On a science forum I read occasionally, a person who was just taking their first quantum mechanics class asked just how exactly you would go about preparing a system such as a hydrogen atom in a particular quantum state. It was correctly suggested that at room temperature, pretty much all of the atoms would automatically be in the ground state by virtue of the first excited energy level of the hydrogen atom is quite a bit bigger than kT. From there you could do things like shine a laser tuned to the transition frequency to put the atoms in your desired state. This is all true as far as it goes.
I decided to run the numbers and see just exactly what the percentage of hydrogen atoms are in the ground state at room temperature of roughly 300 K. To describe what I did (and how I did it wrong), I need to give you just a little background in statistical mechanics.
Imagine you’re playing poker. You draw 5 cards, and if you’re very lucky you might get a royal flush. There are four ways this might happen, one for each suit. Therefore, the odds of you getting a royal flush are four out of… how many times? To find out, you need to calculate how many possible hands there are. Then the probability of that royal flush will be 4 divided by however many possible hands there are.
Statistical mechanics works along the same lines. You figure out the unweighted probability of the state you’re interested in – this is just the number of combinations that form the state (4 for a royal flush) times a factor called the Boltzmann factor which tells you how the probability of the state varies with the temperature of the system. Then you divide by the total number of states, with each one weighted by the Boltzmann factor appropriate to its energy. This latter sum is called the partition function.
All this is to say that the probability of finding a particle in a particular state n is given by the equation below. Don’t worry about trying to derive it from the rather vague paragraph above, if you’re interested in the details and somewhat masochistic you can find them in any good statistical mechanics textbook. The equation:

Where Z is the partition function:

The g_n is the degeneracy, which happens to be n^2 for the hydrogen atom (neglecting small effects which are not crucial here). The energy levels E_n for the hydrogen atom are well-known. They are (defining the ground state as E_1 = 0):

Where R is the Rydberg constant, approximately 13.6 eV. We might as well calculate kT as well – at T = 300K, kT is about 0.02585 eV.
All right! Knowing all that, we can evaluate the sum and calculate Z. The first term involves n = 1, so E_0 = 0 and you end up with e^0 which is 1, multiplied by 1^2 which is also 1. Fine. Then move on to n = 2 and repeat the process. Keep going until you get tired and n will get very big, which means E_n will tend to R, so the factor in the exponent will tend to R/kT. And R/kT is about 526, and I assure you that e^-526 is a tiny, tiny, insanely tiny number.
But it’s not zero, and we’re trying to add an infinite number of them. The partition function is infinite, and the probability of finding a hydrogen atom in any finite n state is therefore 0.
Yikes. What in the world did we do wrong? Well, for starters I’ll admit that I didn’t even look closely enough at the equation to even notice the divergence until Mathematica promptly spat out an overflow error. I was at a loss – surely the equations were right, but equally surely this was such an obvious calculation that if there were anything weird a textbook would have used it as a problem that I’d surely have been assigned. But no, to my knowledge I’d never encountered this issue before. I thought about it for a while, and decided to take a look through the literature. Sure enough, this calculation really does have some subtle features. To be completely honest I’m not sure I’m 100% comfortable with this resolution, but S.J. Strickler in the Journal of Chemical Education (Volume 43, Number 7, July 1966) has published what seems to be a pretty decent resolution of the seeming paradox.
He notes that the quantum mechanical solution for the hydrogen atom has energy levels which scale as 1/n^2, but the spatial extent of the energy levels – the radius of the electron “orbits” – scales as n^2. For the ground state n = 1, the orbit is just about half an angstrom. But by the time you get to n = 10^5 or so, the radius is of macroscopic size, say, 50cm or so. This is not possible in the laboratory. The electron will begin interacting with the vacuum tube or whatever it happens to be in, and the original solution for a hydrogen atom in otherwise free space doesn’t apply. Instead, the potential will begin to look something more like the square well potential, for which the partition function does not diverge. Effectively, you can cut off the sum at n = 10^5 and you’ll have a perfectly acceptable partition function.
This seems a little artificial. Plenty of hydrogen atoms aren’t in laboratory flasks, they’re floating freely in interstellar space. Does this resolution work there? Sure it does. At n = 10^18, the radius of the electron orbit is about the size of the known universe. It seems reasonable to cut off the sum there, and even for such high n the partition function different only infinitesimally from what it would be if you cut it off after just the first few terms.
Perfectly satisfied? Neither am I. Still, it’s an interesting and subtle problem involving some pretty basic concepts, and one I’m happy to have stumbled over.