The properties of galaxies change in a systematic way with galaxy mass, with redshift and with environment. Understanding which factor is the most important in driving galaxy evolution is one of the main goal of the astrophysics. It is well known that several galaxy properties are largely determined by the stellar mass. I will characterize the galaxy stellar mass function in different global environments (clusters, groups, field), at intermediate redshift. Then, I will present in detail the mass function of galaxies in clusters, as a function of the galaxy morphological type, and how it evolves between z=0.8 and z=0. This results that has several far reaching implications for the mass assembly, the mass segregation with environment and the morphological evolution of galaxies. I can show how strong is the evolution of the total mass function, and of the mass function of EACH morphological types (ellipticals, S0s and late-types) in clusters, and discuss the possible processes that cause this. Then, I will discuss also the role of the local density in shaping the mass distribution and I will show how the local environment is more important than the global one in influencing the mass function.