I'm not sure what your question is, but if you want to understand how it works, you will have to study the "Discrete Time Fourier Trasform" (DTFT) and "Discrete Fourier Transform" (DFT). This is the discrete time, discrete frequency version of the continuous Fourier transform. "Fast Fourier Transfrom" (FFT) is a fast algorithm to compute the DFT. You can easily find many tutorials online on these topics.
Mathematically there is an elegant theory for Fourier transforms and if you are an engineer it will be worth it to invest the time to know the theory. The equivalence of the variance and the sum of squares of the fourier coefficients comes from there and is known as Parseval's theorem. Another way to say it is that the fourier transform maps the space of square summable sequences (square integrable functions in the continuous case) onto the same space and preserves distance in that space (this is called isometry).
The naive implementation of dft is simple. fft is more involved so this is not the place to describe it, but you can find the implementation in some textbooks. A good textbook is "Linear Algebra and its applications" by Gilbert Strang.