We discuss surface alloy phases and their stability based on surface phase diagrams constructed from the surface energy as a function of the surface composition. We show that in the simplest cases of pseudomorphic overlayers there are four generic classes of systems, characterized by the sign of the heat of segregation from the bulk and the sign of the excess interactions between the atoms in the surface ͑the surface mixing energy͒. We also consider the more complicated cases with ordered surface phases, nonpseudomorphic overlayers, second layer segregation, and multilayers. The discussion is based on density-functional calculations using the coherent-potential approximation and on effective-medium theory. We give self-consistent density-functional results for the segregation energy and surface mixing energy for all combinations of the transition and noble metals. Finally we discuss in detail the cases Ag/Cu͑100͒, Pt/Cu͑111͒, Ag/Pt͑111͒, Co/Cu͑111͒, Fe/Cu͑111͒, and Pd/Cu͑110͒ in connection with available experimental results.