We present a new near-infrared imaging survey in the four CFHTLS deep fields: the WIRCam Deep Survey or "WIRDS". WIRDS comprises extremely deep, high quality (FWHM ∼ 0.6 ) J, H, and K s imaging covering a total effective area of 2.1 deg 2 and reaching AB 50% completeness limits of ≈24.5. We combine our images with the CFHTLS to create a unique eight-band ugrizJHK S photometric catalogues in the four CFHTLS deep fields; these four separate fields allow us to make a robust estimate of the effect of cosmic variance for all our measurements. We use these catalogues in combination with ≈9800 spectroscopic redshifts to estimate precise photometric redshifts (σ Δz/(1+z) 0.03 at i < 25), galaxy types, star-formation rates and stellar masses for a unique sample of ≈1.8 million galaxies. Our JHK s number counts are consistent with previous studies. We apply the "BzK" selection to our gzK filter set and find that the star forming BzK selection successfully selects 76% of star-forming galaxies in the redshift range 1.4 < z < 2.5 in our photometric catalogue, based on our photometric redshift measurement. Similarly the passive BzK selection returns 52% of the passive 1.4 < z < 2.5 population identified in the photometric catalogue. We present the mass functions of the total galaxy population as a function of redshift up to z = 2 and present fits using double Schechter functions. A mass-dependent evolution of the mass function is seen with the numbers of galaxies with masses of M 10 10.75 still evolving at z 1, but galaxies of higher mass reaching their present day numbers by z ∼ 0.8−1. This is consistent with the present picture of downsizing in galaxy evolution. We compare our results with the predictions of the GALFORM semi-analytical galaxy formation model and find that the simulations provide a relatively successful fit to the observed mass functions at intermediate masses (i.e. 10 log (M/M ) 11). However, as is common with semi-analytical predictions of the mass function, the GALFORM results under-predict the mass function at low masses (i.e. log (M/M ) 10), whilst the fit as a whole degrades beyond redshifts of z ∼ 1.2. All photometric catalogues and images are made publicly available from TERAPIX and CADC.