Codomain can be referred to as the whole set of a possible outcome that can possibly come out of a function, it is part of the definition of a function, and do restricts the function outputs too, while range refers to the outcome based on a defined function, that is, the set of values produced as a result of the functional relationship between the domain and codomain.
The Codomain contains the set of range, but the range is a part of the Codomain. The Codomain is meant to set a restriction for the outcome values, where the restriction, as defined by the function, is the range. For example, if a set is defined as A= {1, 2, 3, 4}, and B= {1, 2, 5, 8, 9}, and the functional relation f: A->B is defined as f(x) =2x. Therefore, the codomain is set B {1, 2, 5, 8, 9} while the range = {2, 8}.