The codomain of a function is the set B — the collection of possible outputs. Not every element of the codomain need actually appear as an output. Those that do form the image (or range) of f. A function is surjective when its image equals its entire codomain — every possible output is actually hit.
The codomain is part of the function’s specification, not a consequence of its rule. The function viewed as has codomain and is not surjective (negative numbers are never outputs). The same rule viewed as has a smaller codomain and is surjective. These are different functions because they have different codomains, even though they assign the same output to every input.
The codomain of a binary relation is the set B — the set from which the second components of the ordered pairs are drawn.
In a category, the codomain of a morphism is the target object B. Composition requires the codomain of the first morphism to match the domain of the second: is defined only when the codomain of equals the domain of . This matching condition is the basic constraint on which morphisms can be chained together.