Solvation significantly affects the basicity of amines.  N-H groups strongly interact with water, especially in ammonium ions. Consequently, the basicity of ammonia is enhanced by 10 by solvation. The intrinsic basicity of amines, i.e. the situation where solvation is unimportant, has been evaluated in the gas phase.  In the gas phase, amines exhibit the basicities predicted from the electron-releasing effects of the organic substituents.  Thus tertiary amines are more basic than secondary amines, which are more basic than primary amines, and finally ammonia is least basic.  The order of pK's (basicities in water) does not follow this order.  Similarly aniline is more basic than ammonia in the gas phase, but ten thousand times less so in aqueous solution.
In aprotic polar solvents such as DMSO, DMF, and acetonitrile the energy of solvation is not as high as in protic polar solvents like water and methanol.  For this reason, the basicity of amines in these aprotic solvents is almost solely governed by the electronic effects.