Fix (not necessarily distinct) objects i and j of a locally small category S, and write S ij for the set of all morphisms i → j. Fix a morphism a ∈ S ji , and define an operation a on S ij by x a y = xay for all x, y ∈ S ij . Then (S ij , a ) is a semigroup, known as a sandwich semigroup, and denoted by S a ij . This article develops a general theory of sandwich semigroups in locally small categories. We begin with structural issues such as regularity, Green's relations and stability, focusing on the relationships between these properties on S a ij and the whole category S. We then identify a natural condition on a, called sandwich regularity, under which the set Reg(S a ij ) of all regular elements of S a ij is a subsemigroup of S a ij . Under this condition, we carefully analyse the structure of the semigroup Reg(S a ij ), relating it via pullback products to certain regular subsemigroups of S ii and S jj , and to a certain regular sandwich monoid defined on a subset of S ji ; among other things, this allows us to also describe the idempotentgenerated subsemigroup E(S a ij ) of S a ij . We also study combinatorial invariants such as the rank (minimal size of a generating set) of the semigroups S a ij , Reg(S a ij ) and E(S a ij ); we give lower bounds for these ranks, and in the case of Reg(S a ij ) and E(S a ij ) show that the bounds are sharp under a certain condition we call MI-domination. Applications to concrete categories of transformations and partial transformations are given in Part II.The concept of stability played a crucial role in [9], and will continue to do so here. Recall that a partial semigroup S is stable if, for all a, x ∈ S,In our studies, we require a more refined notion of stability. We say an element a of a partial semigroupWe say a is stable if it is both R-and L -stable.Recall that a semigroup T is periodic if for each x ∈ T , some power of x is an idempotent: that is, x 2m = x m for some m ≥ 1. It is well known that all finite semigroups are periodic; see for example [25, Proposition 1.2.3]. The proof of the next result is adapted from that of [43, Theorem A.2.4], but is included for convenience. If a ∈ S ji , for some i, j ∈ I, then S ij a is a subsemigroup of S i , and aS ij a subsemigroup of S j . We will have more to say about these subsemigroups in Sections 2 and 3. Lemma 1.3. Let S be a partial semigroup, and fix i, j ∈ I and a ∈ S ji .