TiC/a-C:H nanocomposite coatings have been deposited by magnetron sputtering and are composed of 2-5nm TiC nanocrystallites well separated by amorphous hydrocarbon (a-C:H) of about 2nm separation width. A transition from columnar to glassy microstructure has been observed with increasing substrate bias or carbon content. Micro-cracks induced by nanoindentation or wear tests readily propagate through the column boundaries whereas the coatings without a columnar microstructure show supertough behavior. The nanocomposite coatings exhibit hardness of 5~20 GPa, superior wear resistance and strong self-lubrication effects with a friction coefficient of 0.05 in air and 0.01 in nitrogen under dry sliding against uncoated bearing steel balls. Especially, the transitions from low to ultralow friction or the reverse are repeatedly switchable if the atmosphere is cycled between ambient air and nitrogen. The lowest wear rate is obtained at high humidity.