Sampling Frequency Math
Sampling a continuous signal $x(t)$ can be modeled by multiplication with a delta pulse train:

$$x_s(t)=x(t)\cdot\sum_{n=-\infty}^{\infty}\delta(t-nT)=
\sum_{n=-\infty}^{\infty}x(nT)\delta(t-nT)$$

where $T$ is the sampling interval: $T=1/f_s$ ($f_s$ is the sampling frequency). Multiplication in the time-domain corresponds to convolution in the frequency domain. So the spectrum of the sampled signal can be computed by convolving the transforms of $x(t)$ and of the pulse train:

$$x(t)\Longleftrightarrow X(f)\\
\sum_{n=-\infty}^{\infty}\delta(t-nT)\Longleftrightarrow
\frac{1}{T}\sum_{k=-\infty}^{\infty}\delta(f-kf_s)
$$

Convolution of these two Fourier transforms gives

$$x_s(t)\Longleftrightarrow X_s(f)=
\frac{1}{T}\sum_{k=-\infty}^{\infty}X(f-kf_s)\tag{1}$$

Equation (1) shows that the spectrum of a sampled signal is composed of shifted versions of the original spectrum. The shift corresponds to multiples of the sampling frequency $f_s$. Consequently, if the spectrum $X(f)$ is exactly zero for frequencies greater than $f_s/2$, then the shifted versions do not overlap, and the original spectrum can be reconstructed by lowpass filtering the spectrum of the sampled signal. If $X(f)$ is not band-limited to $f_s/2$, i.e. it has frequency components greater than $f_s/2$, the shifted spectra in Equation (1) overlap, and the original signal can in general not be reconstructed from the sampled signal. This is what the sampling theorem states.

EDIT: For non-periodic signals - i.e. if $X(f)$ does not contain Dirac impulses - it is sufficient for reconstruction that $X(f)$ does not contain frequency components above $f_s/2$. In this case it is (theoretically) possible to reconstruct $x(t)$ from its samples $x(nT)$ by applying an ideal lowpass filter with cut-off frequency $f_s/2$. The impulse response of such an ideal lowpass filter is given by

$$h_{LP}(t)=\frac{\sin (\pi t/T)}{\pi t/T}$$

Filtering $x_s(t)$ with this impulse response yields the original signal

$$x(t)=\sum_{n=-\infty}^{\infty}x(nT)\frac{\sin [\pi (t-nT)/T]}{\pi (t-nT)/T}\tag{2}$$

Equation (2) is usually referred to as the Whittaker-Shannon interpolation formula.

Normally one does not need to consider what is actually happening at the frequency $f_s/2$. The only case where this is necessary is the presence of a pure sinusoid with frequency $f_s/2$. From Equation (1) we can see that in this case the shifted spectra (for $k=\pm 1$) will also produce spectral lines at $\pm f_s/2$, which in general will make impossible the reconstruction of the sinusoid at $f_s/2$. Apart from this somewhat artificial case, it suffices to require that the signal does not contain any frequency components greater than $f_s/2$.

The above considerations are of course of a purely theoretical nature, because there exist neither ideally band-limited signals nor ideal lowpass filters. Consequently, in practice we will choose the sampling frequency such that it is well above twice the maximum signal frequency of interest. The anti-aliasing filter must pass frequencies up to this maximum frequency, then it has a finite transition bandwidth, and then we can choose a frequency in the stopband of the filter where the stopband attenuation guarantees that aliasing errors are sufficiently small for the given application. This frequency can finally be considered the "bandwidth" $B$, and the sampling frequency can now be chosen as $f_s\ge 2B$.