A weather balloon rises through the atmosphere, and the temperature changes as the balloon climbs. If height depends on time and temperature depends on height, then temperature also depends on time. That chain of dependence is one of the most powerful ideas in algebra. It lets us connect quantities that are not linked directly, but through an intermediate step.
[Figure 1] Many real situations work this way. A phone battery's remaining charge may depend on screen brightness, and screen brightness may depend on ambient light. The cost of shipping may depend on package mass, while mass may depend on how many items are packed. In each case, one quantity feeds into another.
When one function's output becomes the input of another, we use the notation for composite functions. This helps us write a single function to describe a multi-step relationship clearly and efficiently.
A function matches each input with exactly one output. If \(f(x) = 2x + 3\), then the input is \(x\) and the output is \(2x + 3\). Composition builds on that same input-output idea, but in two stages.
Composition appears whenever one measured quantity is used to calculate another. In science, medicine, economics, and engineering, this is common because systems are often linked in layers rather than in one direct step.
Suppose \(g(x)\) gives one result, and then \(f\) takes that result as its input. The combined process is written as \(f(g(x))\). The inner function works first, and the outer function works second. This chaining process is the core idea of composition.
If \(h(t)\) is the height of a balloon at time \(t\), and \(T(y)\) is the atmospheric temperature at height \(y\), then \(T(h(t))\) means: first find the balloon's height at time \(t\), then use that height to find the temperature there. The variable name does not matter as much as the role it plays. What matters is that the output of \(h\) becomes the input of \(T\).

This is why composition is sometimes described as a "function of a function." But it is better to think of it as a process: do one function, then feed the result into another.
Composition of functions means forming a new function by using the output of one function as the input of another.
The notation \((f \circ g)(x)\) means the same thing as \(f(g(x))\).
Inner function means the function applied first. Outer function means the function applied second.
Order matters. In general, \(f(g(x))\) is not the same as \(g(f(x))\). Even when both expressions are defined, they often produce different outputs.
To interpret a composite function, identify the quantities and their units. In the balloon example, \(t\) might be measured in minutes, \(h(t)\) in kilometers, and \(T(y)\) in degrees Celsius. Then \(T(h(t))\) gives temperature in degrees Celsius as a function of time in minutes.
This is a major modeling skill: write a function that describes a relationship between two quantities even when they are connected through an intermediate quantity. If one relationship is "time to height" and another is "height to temperature," composition creates "time to temperature."
Here are several common patterns:
Notice the pattern: the output unit of the inner function must match the input unit of the outer function.
[Figure 2] To calculate a composite function algebraically, substitute the entire inner expression into the outer function. If \(f(x) = 3x - 2\) and \(g(x) = x^2 + 1\), then \((f \circ g)(x) = f(g(x)) = f(x^2 + 1)\). You replace every input of \(f\) with \(x^2 + 1\).
The order of composition matters. One path sends the input through \(g\) first and then through \(f\); the other reverses the order. Because each function transforms values differently, the final results can differ.

Using the same functions, we get \((f \circ g)(x) = 3(x^2 + 1) - 2 = 3x^2 + 1\). But \((g \circ f)(x) = g(f(x)) = g(3x - 2) = (3x - 2)^2 + 1\), which simplifies to \(9x^2 - 12x + 5\). These are clearly different expressions.
Worked example 1: composing two algebraic functions
Let \(f(x) = 2x + 5\) and \(g(x) = x^2 - 3\). Find \((f \circ g)(x)\) and \((g \circ f)(x)\).
Step 1: Find \((f \circ g)(x)\).
Start with \(f(g(x))\). Since \(g(x) = x^2 - 3\), substitute into \(f\): \(f(x^2 - 3) = 2(x^2 - 3) + 5\).
Step 2: Simplify.
\(2(x^2 - 3) + 5 = 2x^2 - 6 + 5 = 2x^2 - 1\).
Step 3: Find \((g \circ f)(x)\).
Start with \(g(f(x))\). Since \(f(x) = 2x + 5\), substitute into \(g\): \(g(2x + 5) = (2x + 5)^2 - 3\).
Step 4: Expand and simplify.
\((2x + 5)^2 - 3 = 4x^2 + 20x + 25 - 3 = 4x^2 + 20x + 22\).
So, \[(f \circ g)(x) = 2x^2 - 1\] and \[(g \circ f)(x) = 4x^2 + 20x + 22\].
These two results are different, which shows that composition is not usually commutative. In other words, \(f \circ g \neq g \circ f\) in general.
One of the most important ideas in composition is the domain. A composite function is defined only when the inner function gives outputs that the outer function is allowed to accept. You must check both functions together.
For example, if \(f(x) = \sqrt{x}\) and \(g(x) = 5 - x\), then \((f \circ g)(x) = \sqrt{5 - x}\). Since a square root requires the inside to be nonnegative, we need \(5 - x \geq 0\). That means \(x \leq 5\).

So even if \(g(x)\) is defined for all real numbers, the composite \(f(g(x))\) is only defined for inputs that make \(g(x)\) land inside the domain of \(f\).
How to check a composite domain
First, find the inner function. Second, determine the kinds of outputs the outer function allows. Third, require the inner expression to satisfy those conditions. For square roots, the inside must be at least \(0\). For rational functions, denominators cannot be \(0\). For logarithms, the input must be positive.
This idea is especially important when formulas model real life. A function might make algebraic sense, but a context may still restrict the domain. For example, time is usually \(t \geq 0\), mass cannot be negative, and a population count must be a whole number if the situation requires it.
Worked example 2: composition with a domain restriction
Let \(f(x) = \sqrt{x + 4}\) and \(g(x) = 2x - 1\). Find \((f \circ g)(x)\) and its domain.
Step 1: Compose the functions.
\((f \circ g)(x) = f(g(x)) = f(2x - 1) = \sqrt{(2x - 1) + 4} = \sqrt{2x + 3}\).
Step 2: Apply the square root condition.
For \(\sqrt{2x + 3}\) to be defined, we need \(2x + 3 \geq 0\).
Step 3: Solve the inequality.
\(2x \geq -3\), so \(x \geq -\dfrac{3}{2}\).
The composite is \[(f \circ g)(x) = \sqrt{2x + 3}\] with domain \[x \geq -\frac{3}{2}\].
As we saw, the domain of a composite often comes from a restriction created by the outer function, not just the inner one.
Real-world compositions are often easier to understand because the variables represent actual quantities. The key is to ask, "What does the inner function produce?" and "Can the outer function use that result?"
Worked example 3: weather balloon model
A weather balloon's height after \(t\) minutes is \(h(t) = 0.4t + 1\), where height is in kilometers. The atmospheric temperature at height \(y\) kilometers is \(T(y) = 18 - 6y\), where temperature is in degrees Celsius. Find \(T(h(t))\) and interpret it.
Step 1: Identify the inner and outer functions.
The inner function is \(h(t) = 0.4t + 1\). The outer function is \(T(y) = 18 - 6y\).
Step 2: Substitute \(h(t)\) into \(T\).
\(T(h(t)) = 18 - 6(0.4t + 1)\).
Step 3: Simplify.
\(18 - 6(0.4t + 1) = 18 - 2.4t - 6 = 12 - 2.4t\).
Step 4: Interpret the result.
The temperature at the balloon's location after \(t\) minutes is \(12 - 2.4t\) degrees Celsius.
So, \[T(h(t)) = 12 - 2.4t\].
[Figure 3] This composition turns a "height from time" rule and a "temperature from height" rule into a "temperature from time" rule. That is exactly what composition is designed to do.
Worked example 4: shipping cost
A company packs \(n\) identical sensors into a box. The total mass is \(m(n) = 0.25n + 1.5\), in kilograms. Shipping cost is \(C(m) = 4m + 6\), in dollars. Find \(C(m(n))\).
Step 1: Compose the functions.
\(C(m(n)) = 4(0.25n + 1.5) + 6\).
Step 2: Simplify.
\(4(0.25n + 1.5) + 6 = n + 6 + 6 = n + 12\).
Step 3: Interpret.
The shipping cost depends directly on the number of sensors: for \(n\) sensors, the cost is \(n + 12\) dollars.
The composite function is \[C(m(n)) = n + 12\].
[Figure 4] Although the original problem involved mass and then cost, composition produced a new rule in terms of number of sensors alone.
Not every function is given by a formula. Sometimes a function is shown with a table, and the composition must be evaluated in two lookups.
Suppose a table tells you that \(g(2) = 5\) and another row shows that \(f(5) = 9\). Then \((f \circ g)(2) = f(g(2)) = f(5) = 9\).

The same logic works with graphs. If you can read \(g(2)\) from the graph of \(g\), then you use that result as the input on the graph of \(f\). Composition is still a two-step process even when there is no equation to simplify.
| Input \(x\) | \(g(x)\) | Then \(f(g(x))\) |
|---|---|---|
| \(1\) | \(3\) | If \(f(3) = 8\), then \((f \circ g)(1) = 8\) |
| \(2\) | \(5\) | If \(f(5) = 9\), then \((f \circ g)(2) = 9\) |
| \(4\) | \(1\) | If \(f(1) = 6\), then \((f \circ g)(4) = 6\) |
Table 1. Example of evaluating a composite function from table values in two steps.
Later, when you work with inverse functions, transformations, and more advanced models, this two-step viewpoint becomes even more important. Composition is one of the basic structures that connects many areas of algebra.
Composed functions appear everywhere. In medicine, a drug concentration in the bloodstream may depend on dosage, while dosage may depend on body mass. In economics, tax owed may depend on income, while income may depend on hours worked. In engineering, pressure may depend on depth, while depth may depend on time as a robot submarine descends.
In environmental science, the balloon example is especially meaningful. Meteorologists often build layered models: altitude from time, pressure from altitude, temperature from pressure, and humidity from temperature. Large scientific models may involve many compositions chained together.
Space missions and climate models often rely on long chains of functions. A single prediction may pass through several stages, where each stage transforms the previous result into a new quantity.
Composition also appears in computer science. A program may first convert raw sensor data into a cleaned measurement, then convert that measurement into a decision. Mathematically, that is still a function feeding into another function.
One common mistake is reversing the order. If the situation says "height depends on time" and "temperature depends on height," then the correct composition is \(T(h(t))\), not \(h(T(t))\). The second expression may not even make sense because temperature is not a time input.
Another mistake is treating composition like multiplication. The expression \(f(g(x))\) does not mean \(f \cdot g \cdot x\). It means substitute the entire output of \(g(x)\) into \(f\).
A third mistake is ignoring the domain. As we saw earlier and again in [Figure 4] when values are traced step by step, every stage must be valid. If the inner function produces a value the outer function cannot accept, then the composite is undefined for that input.
"The output of one process becomes the input of the next."
— A useful principle for understanding composition
When checking your work, ask three questions: What happens first? What comes out of that step? Can the next function accept that output? If you can answer those clearly, you are using composition correctly.