We derive for the first time the dust mass function ( DMF ) in a wide redshift range , from z \sim 0.2 up to z \sim 2.5 . In order to trace the dust emission , we start from a far-IR ( 160- \mu m ) Herschel selected catalogue in the COSMOS field . We estimate the dust masses by fitting the far-IR data ( \lambda _ { rest } \buildrel > \over { \sim } 50 \mu m ) with a modified black body function and we present a detailed analysis to take into account the incompleteness in dust masses from a far-IR perspective . By parametrizing the observed DMF with a Schechter function in the redshift range 0.1 < z { \leq } 0.25 , where we are able to sample faint dust masses , we measure a steep slope ( \alpha \sim 1.48 ) , as found by the majority of works in the Local Universe . We detect a strong dust mass evolution , with M _ { d } ^ { \star } at z \sim 2.5 almost one dex larger than in the local Universe , combined with a decrease in their number density . Integrating our DMFs we estimate the dust mass density ( DMD ) , finding a broad peak at z \sim 1 , with a decrease by a factor of \sim 3 towards z \sim 0 and z \sim 2.5 . In general , the trend found for the DMD mostly agrees with the derivation of Driver et al . ( 2018 ) , another DMD determination based also on far-IR detections , and with other measures based on indirect tracers .