Differentiation from First Principles
The gradient of a curve at a point is the limit of a chord's gradient as the two points merge. That limit — the derivative — is where all of calculus begins.
The gradient of a curve at a point
For a straight line, "gradient" is a single number — rise over run, the same everywhere. A curve is different: its steepness changes from point to point. So what could the gradient at a single point even mean? The answer is the key idea of all calculus: the gradient of a curve at a point is the gradient of the tangent to the curve there — the straight line that just grazes the curve at that point.
The problem is that a tangent touches at only one point, and you need two points to compute a gradient. Differentiation from first principles solves this with a clever limiting trick: start with a chord joining two nearby points, then slide the second point closer and closer to the first, watching what the chord's gradient approaches.
Take a point $P(x, f(x))$ and a second point $Q$ a small horizontal distance $h$ away, at $(x+h,\ f(x+h))$. The chord $PQ$ has gradient $\dfrac{f(x+h) - f(x)}{h}$ — an ordinary rise-over-run. As $h$ shrinks toward $0$, $Q$ slides into $P$ and the chord rotates until it is the tangent. The tangent's gradient is therefore the limit of the chord's gradient as $h\to 0$. That limit is the derivative.
The definition
Writing $f'(x)$ (read "f-dash of x") for the derivative, the definition is
The notation $\lim_{h\to 0}$ means "the value this expression approaches as $h$ gets arbitrarily close to $0$". You can't just set $h=0$ — that gives $\tfrac{0}{0}$, which is meaningless. The whole technique is to simplify first so the troublesome $h$ in the denominator cancels, and only then let $h\to 0$.
Every first-principles derivation follows the same four moves: (1) write out $f(x+h)$; (2) form $f(x+h) - f(x)$ and simplify the numerator; (3) divide every term by $h$, cancelling the denominator; (4) let $h\to 0$ and read off what survives. If step 3 leaves an $h$ still stuck in a denominator, you haven't simplified enough in step 2.
Worked example 1
The magic is in step 3: because every term of the numerator contained an $h$, dividing by $h$ removed it from the denominator entirely, leaving $2x + h$ — an expression you can safely evaluate at $h=0$. Notice we never divided by zero; we cancelled the $h$ while it was still non-zero, then took the limit.
Worked example 2
Look at the two results together: $x^2 \to 2x$ and $x^3 \to 3x^2$. In each case the power dropped by one and the old power appeared as a multiplier out front. That's not a coincidence — it's the general power rule $\dfrac{d}{dx}(x^n) = nx^{n-1}$, and first principles is why it holds. Once you've seen it proved twice, you can use the shortcut with confidence in the next lesson.
Worked example 3
Notice $f'(x) = 2x - 4$ is itself a formula, not a single number: feed in any $x$ and it returns the gradient there. That's why $f'$ is called the gradient function or derived function. To get the gradient at a particular point, you evaluate this function at that point — as we did with $f'(3) = 2$. One derivation, then a gradient anywhere on the curve.
You cannot reach the answer by setting $h=0$ at the start — $\dfrac{f(x+h)-f(x)}{h}$ becomes $\tfrac00$, which is undefined. The $h$ must be cancelled from the denominator first (step 3), and only then may you let $h\to 0$. Also, expand $(x+h)^2$ and $(x+h)^3$ in full — writing $(x+h)^2 = x^2 + h^2$ (forgetting the $2xh$) collapses the whole derivation.
Check yourself
Use first principles to show that if $f(x) = 3x^2 + 2$, then $f'(x) = 6x$. Hence find the gradient of the curve at $x = -1$.
(Hint: expand $3(x+h)^2 + 2$, subtract $f(x)$, divide by $h$, then let $h\to 0$.)
The constant $+2$ vanished the moment we formed the numerator — constants have zero gradient, which is why the derivative of any constant is $0$. The gradient at $x=-1$ is $-6$ (a steep, downward slope).