We define the characteristic cycle of an étale sheaf as a cycle on the cotangent bundle of a smooth variety in positive characteristic using the singular support recently defined by Beilinson. We prove a formula à la Milnor for the total dimension of the space of vanishing cycles and an index formula computing the Euler–Poincaré characteristic, generalizing the Grothendieck–Ogg–Shafarevich formula to higher dimension. An essential ingredient of the construction and the proof is a partial generalization to higher dimension of the semi-continuity of the Swan conductor due to Deligne–Laumon. We prove the index formula by establishing certain functorial properties of characteristic cycles.