The rank of a finite semigroup is the smallest number of elements required to generate the semigroup. A formula is given for the rank of an arbitrary (not necessarily regular) Rees matrix semigroup over a group. The formula is expressed in terms of the dimensions of the structure matrix, and the relative rank of a certain subset of the structure group obtained from subgroups generated by entries in the structure matrix, which is assumed to be in Graham normal form. This formula is then applied to answer questions about minimal generating sets of certain natural families of transformation semigroups. In particular, the problem of determining the maximum rank of a subsemigroup of the full transformation monoid (and of the symmetric inverse semigroup) is considered.