We made theoretical calculations for a benzonitrile molecule and its clusters in the gas phase and as adsorbed on the Au(111) surface, to explain the observation by scanning tunneling microscope, that is, the trimer formation of cyanophenyl porphyrins adsorbed onto the Au(111) surface. With regard to the gas-phase species, ab initio calculations showed that (1) the benzonitrile dimer has a single stable structure that is planar and antiparallel; (2) the trimer has two isoenergetic stable structures, that is, a planar and cyclic structure and an antiparallel and nonplanar one; (3) the clusters are more stable, at low temperatures, than the monomer. For the adsorbed species, we made quantum mechanical/molecular mechanical calculations in which the interaction between the adsorbates and the surface is evaluated in a molecular-mechanical way by using analytical potential functions and an image charge model. Because the stable structures were found to be similar to those in the gas phase, the cluster formation of adsorbed cyanophenyl porphyrins was attributed to the interaction between cyanophenyl groups, which is barely affected by adsorbate-surface interaction. It was also found that the adsorbed cyclic benzonitrile trimer is more stable than the monomer and the dimer because the relative stability is dependent on enthalpy alone. We therefore concluded that the preferential formation of trimers by the adsorbed cyanophenyl porphyrins is due to the negligible contribution of entropy to the relative stability of the adsorbed species and that the adsorption hardly changes the situation found in the gas phase.