The sub-ohmic spin-boson model is known to possess a novel quantum phase transition at zero temperature between a localised and delocalised phase. We present here an analytical theory based on a variational ansatz for the ground state, which describes a continuous localization transition with mean-field exponents for $0<s<0.5$. Our results for the critical properties show good quantitiative agreement with previous numerical results, and we present a detailed description of all the spin observables as the system passes through the transition. Analysing the ansatz itself, we give an intuitive microscopic description of the transition in terms of the changing correlations between the system and bath, and show that it is always accompanied by a divergence of the low-frequency boson occupations. The possible relevance of this divergence for some numerical approaches to this problem is discussed and illustrated by looking at the ground state obtained using density matrix renormalisation group methods.