Carbon and carbon nitride films, grown in argon or nitrogen discharges by reactive dc magnetron sputtering of a graphite target, were characterized by in situ scanning tunneling microscopy. When the growth temperature increased from ambient to 800°C, we observed a topographic evolution of the carbon films from an amorphous to a graphitelike structure, and further to a distorted-graphitic phase with curved and intersecting basal planes, and finally to a surface containing nanotubes and nanodomes. When nitrogen was incorporated into the films, distortion of the graphitic basal planes occurred at a lower temperature compared to the pure carbon case. At temperatures of ϳ200°C and above, regions of a nongraphitic phase, containing a high degree of carbon sp 3 bonds were observed. Spatially resolved tunneling spectroscopic measurements indicated that the band gaps were 0, ϳ0-0.6 eV, and ϳ0.4-2.0 eV for graphitelike structures, the distorted-graphitic phase, and the nongraphitic phase, respectively. Together with ex situ x-ray photoelectron spectroscopy and reflection electron energy loss spectroscopy measurements, the results suggest that the incorporation of nitrogen promotes bending of the graphitic basal planes and thereby facilitates the formation of three-dimensional covalently bonded networks with a high degree of sp 3 -coordinated carbon atoms.