The codomain of a function is the set designated as its target. In the notation (f:A\to B), (A) is the domain, or set of inputs, and (B) is the codomain: every value (f(x)) must belong to (B). The codomain differs from the image, which consists precisely of the values attained by the function. Consequently, some codomain elements may never occur as outputs. This distinction matters when describing surjectivity, inverse functions, and the composition of mappings. (jirka.org)
Definition and notation
In set theory, a function (f:A\to B) assigns exactly one element of (B) to each element of (A). Its graph is the set [ \Gamma_f={(x,f(x)):x\in A}, ] a subset of the Cartesian product (A\times B). Each member of the graph is an ordered pair recording an input and its output. The image of the whole domain is [ f(A)={f(x):x\in A}, ] and necessarily (f(A)\subseteq B). (jirka.org)
There are different conventions for what constitutes a function as a mathematical object. A graph-based convention identifies a function with its input–output pairs, while a convention with specified source and target includes the domain and codomain as additional data. Under the latter convention, changing the codomain produces a different function even if every input retains its previous output. In categorical treatments, the specified target is essential to the identity of an arrow. (pages.jh.edu)
Codomain versus image
Consider the function on the real numbers [ f:\mathbb R\to\mathbb R,\qquad f(x)=x^2. ] Its codomain is (\mathbb R), but its image is ([0,\infty)): squares are nonnegative, and every nonnegative real number is a square. Negative numbers belong to the codomain without being attained. The same rule also defines [ g:\mathbb R\to[0,\infty),\qquad g(x)=x^2. ] The two mappings have identical input–output pairs but different specified targets. (pages.jh.edu)
A formula alone therefore need not determine a codomain. The rule (f(x)=1/x), with domain (\mathbb R\setminus{0}), may be presented with codomain (\mathbb R), although its image excludes zero. A constant real-valued function (h(x)=3) may likewise have codomain (\mathbb R) and image ({3}). A target is declared as part of the presentation; the image is determined by the rule and the domain. (math.berkeley.edu)
Surjectivity and inverses
A surjective function, also called an onto function, reaches every element of its codomain: [ f\text{ is surjective}\quad\Longleftrightarrow\quad f(A)=B. ] Thus surjectivity depends on the specified target, not merely on the formula. By contrast, injectivity requires that distinct inputs have distinct outputs. A bijection satisfies both conditions. (jirka.org)
Applied to the square-rule examples above, (f:\mathbb R\to\mathbb R) is not surjective, whereas (g:\mathbb R\to[0,\infty)) is. Neither is injective, because opposite nonzero inputs have the same square. If both domain and codomain are instead ([0,\infty)), the square function is bijective. Its inverse function is the nonnegative square-root function. These examples illustrate that narrowing the codomain can establish surjectivity but cannot, by itself, remove repeated outputs from distinct inputs. (jirka.org)
Changing the codomain
If (f:A\to B) and [ f(A)\subseteq C\subseteq B, ] the same assignment defines a function (A\to C). This change is called a corestriction. The containment condition ensures that no existing output falls outside the new target. Corestricting to (f(A)) always gives a surjective function. This differs from restricting the domain, which removes permitted inputs and may consequently shrink the image. (phil.cmu.edu)
Corestriction also gives the factorization [ A\xrightarrow{\bar f}f(A)\xrightarrow{i}B, ] where (\bar f(x)=f(x)) is surjective and (i) includes the image in the original codomain. The composite has exactly the original assignment. This separates the values actually attained from the larger set in which they are regarded as lying. (phil.cmu.edu)
Composition and categorical targets
For function composition, the standard arrangement is [ f:A\to B,\qquad g:B\to C, ] giving (g\circ f:A\to C), with ((g\circ f)(x)=g(f(x))). The codomain of (f) matches the domain of (g), ensuring that every output of the first mapping is an acceptable input to the second. (math.berkeley.edu)
In category theory, every arrow has a specified source and target, generalizing domain and codomain. The category of sets uses sets as objects and functions with specified domains and codomains as arrows. Other examples use topological spaces and continuous functions, or groups and homomorphisms. Here the target carries mathematical structure, rather than merely identifying a collection of permitted output values. (math.jhu.edu)
Linear maps
In linear algebra, a linear map (T:V\to W) has the vector space (W) as its codomain. Its image (T(V)) is a linear subspace of (W), possibly a proper one. The rank measures the dimension of this image, not automatically the dimension of the codomain. (math.dartmouth.edu)
For example, (T:\mathbb R^2\to\mathbb R^2), defined by (T(x,y)=(x,0)), has the entire plane as codomain but only the horizontal axis as image. Its rank is one. When (W) is finite-dimensional, a linear map is surjective exactly when its rank equals (\dim W), because its image must then be the whole target space. (math.dartmouth.edu)