A function f from a set A to a set B (written f:A→B) is a rule that associates to every element x∈A a unique element y∈B, written y=f(x). Two things can break this: an element of A left with no image at all, or an element of A given two different images — either failure means the relation is not a function.
A is called the domain (the full set of allowed inputs), B is the co-domain (the set outputs are guaranteed to land inside), and the range is the smaller set f(A)={y∈B∣y=f(x) for some x∈A} of values actually produced — always a subset of the co-domain, though it may equal it. A function can be shown in six equivalent ways: a verbal description, an arrow diagram between two sets, a set of ordered pairs, an algebraic rule/formula, a table of values, or a graph — with domain and range read off each form appropriately (e.g. on a graph, domain is the horizontal spread/projection onto the x-axis, and range the vertical spread/projection onto the y-axis).
When the domain sits in R, the vertical line test decides whether a curve represents a function at all: if any vertical line meets the curve more than once, that x-value has two outputs, so it fails. To find a domain algebraically, list every structural restriction the formula carries (a denominator can't be zero, a square root's argument can't be negative, a logarithm's argument must be positive) and intersect them; to find a range, either track how the formula's value changes as x sweeps the domain, or set y=f(x) and solve for x in terms of y to see which y-values are actually achievable.