The covariogram of a measurable set A Rd is the function gA which to each y ∈ Rd associates the Lebesgue measure of A ∩ (y + A). This paper proves two formulas. The first equates the directional derivatives at the origin of gA to the directional variations of A. The second equates the average directional derivative at the origin of gA to the perimeter of A. These formulas, previously known with restrictions, are proved for any measurable set. As a by-product, it is proved that the covariogram of a set A is Lipschitz if and only if A has finite perimeter, the Lipschitz constant being half the maximal directional variation. The two formulas have counterparts for mean covariogram of random sets. They also permit to compute the expected perimeter per unit volume of any stationary random closed set. As an illustration, the expected perimeter per unit volume of stationary Boolean models having any grain distribution is computed.