Function
A function is a rule that assigns exactly one output value to each input value.
Definition
A function is like a machine: put in an input and you always get exactly one output for it. Formally, a function is a relation between a set of inputs (the domain) and a set of outputs (the range) such that every element of the domain pairs with exactly one element of the range, and even more precisely, a function $f: A \to B$ is a subset of the Cartesian product $A \times B$ such that for every $a \in A$ there exists exactly one $b \in B$ with $(a, b) \in f$, where $A$ is the domain and $B$ is the codomain.
Example
A vending machine is a good analogy: press B3 and you always get the same snack, never two different things at random. Algebraically, $f(x) = x^2$ is a function because input $3$ always gives output $9$, while the relation $y^2 = x$ is NOT a function since $x = 4$ gives both $y = 2$ and $y = -2$. The function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = \sin(x)$ maps every real number to a value in $[-1, 1]$, so its range (image) is $[-1, 1]$, a proper subset of the codomain $\mathbb{R}$.
Key Insight
The key rule is one output per input: if an input could produce two different outputs, the relation is not a function. Functions can be represented as equations, tables, graphs, or mappings, and on a graph the vertical line test checks this rule visually, if any vertical line crosses the graph more than once, it is not a function. The concept is foundational to all of mathematics: category theory generalizes functions to morphisms, capturing structure-preserving maps between abstract objects.