Knowledge of the mass function in open clusters constitutes one way to constrain the formation of low-mass stars and brown dwarfs as does the knowledge of the frequency of multiple systems and the properties of disks. The aim of the project is to determine the shape of the mass function in the low-mass and substellar regimes in the pre-main sequence (27 Myr) cluster IC4665, which is located at 350 pc from the Sun. We have cross-matched the near-infrared photometric data from the Eighth Data Release of the UKIRT Infrared Deep Sky Survey (UKIDSS) Galactic Clusters Survey with previous optical data obtained with the Canada-France-Hawaii wide-field camera to improve the determination of the luminosity and mass functions in the low-mass and substellar regimes. The availability of i and z photometry taken with the CFH12K camera on the Canada France Hawaii Telescope added strong constraints to the UKIDSS photometric selection in this cluster, which is located in a dense region of our Galaxy. We have derived the luminosity and mass functions of the cluster down to J=18.5 mag, corresponding to masses of ~0.025 Msun at the distance and age of IC4665 according to theoretical models. In addition, we have extracted new candidate members down to ~20 Jupiter masses in a previously unstudied region of the cluster. We have derived the mass function over the 0.6-0.04 Msun mass range and found that it is best represented by a log-normal function with a peak at 0.25-0.16 Msun, consistent with the determination in the Pleiades.