Diffeomorphism freedom induces a gauge dependence in the theory of spacetime perturbations. We derive a compact formula for gauge transformations of perturbations of arbitrary order. To this end, we develop the theory of Taylor expansions for one-parameter families (not necessarily groups) of diffeomorphisms. First, we introduce the notion of knight diffeomorphism, that generalises the usual concept of flow, and prove a Taylor's formula for the action of a knight on a general tensor field. Then, we show that any one-parameter family of diffeomorphisms can be approximated by a family of suitable knights. Since in perturbation theory the gauge freedom is given by a one-parameter family of diffeomorphisms, the expansion of knights is used to derive our transformation formula. The problem of gauge dependence is a purely kinematical one, therefore our treatment is valid not only in general relativity, but in any spacetime theory.