I warned you not to read the math ;-) It took me a lot of effort to understand what was going on and why it works. Hairiest math I've ever encountered and I'm a 64 year old oil industry geophysicist. But *not* a mathematician.
I was referring to what I call "sprinkling Gauss water on the problem".
Under the assumption of Gaussian distributed, zero mean random noise, as you average more samples, the Gaussian noise reverts to the mean value, zero. But a non-random signal reverts to its mean which is not zero. The mean value of the random noise drops by 1/sqrt(N).
6 dB is 20 * log(2). 8 bits is 48 dB as each bit is double the previous bit. So let's suppose that the fundamental is at 0 dBm and we have a harmonic which is -180 dBm. The dynamic range of a 24 bit ADC is approximately 144dB. In reality it is less, but that's not relevant for this discussion. So to measure the harmonic at -180 dBm we need to get at least 36 dB additional dynamic range. So we need to multiply the signal by 4000 to get the 36dB gain. We're going to do that by adding one term at a time. 5*6 = 6+6+6+6+6. In fact, if you want to *measure* a signal at -180 dB relative to the peak signal, you would need to sum 10,000 samples or more. And make sure that the input signal was at the maximum value of the ADC input.
Because there is abundant time correlated noise at that signal level, 1 nanowatt, we need to take a long recording and randomly select 4000 start times. These *must* be random, so a Mersenne Twister PRNG is required. The frequency resolution is approximately 1/(N*dT) where N is the number of samples and dT is the sample rate. It gets more complicated because the manner in which the ends of the time series are tapered affects the actual resolution. The previous formula just gives the spacing of the frequency bins in the FFT.
There are other complications though. We're doing floating point math and a lot of it. So we have to contend with errors. I don't want to look up a proper estimate. It's seriously tedious and really doesn't matter. The FPU of an x86 is 80 bits. There are arbitrary precision math libraries which will process as many digits as needed. The GLPK package uses this to avoid the limitations of the 80 bit FPU.
Already this is way past what Jim Williams could do with a top line HP instrument. But it gets better.
If we know the fundamental frequency, which is easily measured to high accuracy with a GPSDO referenced counter, then we know *exactly* what the envelope of each peak in the spectrum looks like. A rectangular window in time is a sinc(x) (i.e. sine(x)/x) function. So, we can setup an A matrix in which every row is a term of the form exp(2*Pi*k/dT) (IIRC. I'd check if I were coding this). Then we solve Ax=y using the simplex solver in GLPK and voila! We have a very high accuracy measurement of the THD of the oscillator using a $100 or less sound card and a PC instead of a $10-20K instrument.
The main limitation is how patient are you. High accuracy requires long samples and lots of computer time. But it's easily doable in a few hours to a day to absurd precision and accuracy. Very quickly one would run into ADC errors that would need to be explicitly accounted for in the A matrix. That would probably have to be done in a separate solution of Ax=y where y is the x from the first problem and the A matrix is a model of the ADC errors.
There is a good bit of work to be done in characterizing residual correlated noise and accounting for it. But once you have that, you toss it into the A matrix and throw that part of the answer away. The requirement of knowing the frequency is merely pedagogical. In actual practice, one would simply setup the A matrix for the general case.
Rather long winded, but hopefully I've been clear. So if you decide you'd like to beat Jim Williams's result you don't need an expensive instrument from Keysight. The A matrices get very large, so they way you do those is to write a small program that generates the A matrix and then you feed that to the glpsol executable in GLPK.
There's a bunch of stuff I've glossed over, so if something is not clear, just ask. The process is long winded and messy, but not hard to do.