Contrails, or condensation trails, are clouds of ice crystals formed when hot, moist air from aircraft engines mixes with cold, drier air in the upper atmosphere.
Contrails are similar to cirrus clouds, naturally occurring clouds found at altitudes around 20,000 feet.
Portions of the upper atmosphere are too dry to produce condensation, so aircraft flying through them do not leave contrails.
However, significant areas are cold enough and contain enough water vapor for ice particles to grow, provided small particles are already present. It is hard to make ice form from water vapor unless solid surfaces are present, and such surfaces presented by existing ice crystals are rare in the upper atmosphere.
Ice can form only if the proportion of water vapor in the cold air is particularly high. In such conditions, the addition of a small amount of water vapor from an aircraft can trigger the formation of a contrail or a cloud.
A somewhat similar mechanism is at work on a cold day when your moist, warm, but cloud-free breath meets cold, cloud-free air and a miniature cloud forms.