A relation from A to B is a subset of A×B; its domain is the set of first coordinates that occur and its range is the set of second coordinates that occur.
A function f:A→B assigns exactly one element of B to every element of A; an input cannot have two outputs and no domain input may be left without one.
The codomain B is declared in f:A→B; the range consists only of outputs actually attained and is always a subset of B.