In mathematics, a **semigroup** is a set with an associative binary operation on it.

A semigroup with an identity element is called a monoid. Any semigroup *S* may be turned into a monoid simply by adjoining an element *e* not in *S* and defining *ee* = *e* and *es* = *s* = *se* for all *s* ∈ *S*.

Some examples of semigroups:

- The positive integers with addition.
- Any monoid, and therefore any group.
- Any ideal of a ring, with the operation of multiplication.
- Any subset of a semigroup which is closed under the semigroup operation.
- The set of all finite strings over some fixed alphabet Σ, with string concatenation as operation. If the empty string is included, then this is actually a monoid, called the "free monoid over Σ"; if it is excluded, then we have a semigroup, called the "free semigroup over Σ".

A subset *A* of a semigroup *S* is called a **subsemigroup** if it is closed under the semigroup operation, that is, *AA* is a subset of *A*. If *A* is nonempty then *A* is called a **right ideal** if *AS* is a subset of *A*, and a **left ideal** if *SA* is a subset of *A*. If *A* is both a left ideal and a right ideal then it is called an **ideal** (or a **two-sided ideal**).
The intersection of two ideals is also an ideal, so a semigroup can have at most one minimal ideal.
All nonempty finite semigroups have a minimal ideal.
An example of semigroup with no minimal ideal is the set of positive integers under addition.
The minimal ideal of a commutative semigroup, when it exists, is a group.

If *S* is a semigroup, then the intersection of any collection of subsemigroups of *S* is also a subsemigroup of *S*.
So the subsemigroups of *S* form a complete lattice.
For any subset *A* of *S* there is a smallest subsemigroup *T* of *S* which contains *A*, and we say that *A* **generates** *T*. A single element *x* of *S* generates the subsemigroup { *x*^{n} | *n* is a positive integer }.
If this is finite, then *x* is said to be of **finite order**, otherwise it is of **infinite order**.
A semigroup is said to be **periodic** if all of its elements are of finite order.
Finite semigroups are clearly periodic.
A semigroup generated by a single element is said to be **monogenic** (or **cyclic**). If a monogenic semigroup is infinite then it is isomorphic to the semigroup of positive integers with the operation of addition.
If it is finite, then it must contain an idempotent, in fact, exactly one.
It follows that every nonempty periodic semigroup has at least one idempotent.

A subsemigroup which is also a group is called a **subgroup**. There is a close relationship between the subgroups of a semigroup and its idempotents. Each subgroup contains exactly one idempotent, namely the identity element of the subgroup. For each idempotent *e* of the semigroup there is a unique maximal subgroup containing *e*. Each maximal subgroup arises in this way, so there is a one-to-one correspondence between idempotents and maximal subgroups. (It should be noted that the use of the term *maximal subgroup* is different here than it is in group theory. In group theory, a so-called "maximal subgroup" is really a maximal *proper* subgroup. When considered as a semigroup, a group has only one maximal subgroup, namely itself.)