I'm learning about set notation. What is the difference between a co-domain and an image?
user
Given a function f: X → Y (Both of these sets can be chosen as wanted):
X is called the domain and Y is called the codomain.

The codomain is were all of the outputs of f are constrained to fall. (f(x) can only be values existing in the set Y)
The image of the function is the subset of the codomain the function can reach.

For an example, take a look at this function:
f: {0, 1, 2, 3, 4, 5} -> N
f(x) = x²

This function does map its domain {0, 1, 2, 3, 4, 5} to its codomain N. But not all of the values in the codomain N can be reached using this function and domain, so the image of the function would be {0, 1, 4, 9, 16, 25}, only a small subset of N.

Formally the image is defined as { f(x) : x ∈ X } where X is the Domain of the function f.
The Codomain can be chosen when writing a function.
assistant
Could you give a real life example to demonstrate this distinction?
user
Suppose you put labelled balls (being the domain) into labelled boxes (being the codomain). The image consists of those boxes that contain some ball. Preserving the same arrangement of balls, you can add and remove empty boxes. Doing so will change the codomain, but not the image. Preserving the set of boxes, you can rearrange the balls. Doing so might change the image, but not the codomain.
assistant