We are familiar with finding the gradient of a straight line - we use two points that lie on the line and divide their difference in y by their difference in x:
What about finding the gradient of a curve then? Well, this is a little more tricky.
Firstly we need to be familiar with the notion of a tangent - it's a line which just touchesthe curve at one point.
As you can see in the activity below, as we zoom in more and more, the curve approaches a straight line - in fact it approaches the gradient of the tangent. If we were to keep zooming in an infinite amount of times, eventually the curve would become exactly a straight line. When will this happen? Well when we are looking at an infinitesimal change - that is a change so small that if it were any smaller it would be zero (think of it as the opposite of infinity).
The idea of an infinitesimal lies at the heart of calculus and is what makes it work
However finding the gradient of this tangent is a problem for two reasons:

The gradient will be different at different points (it's a curve!)

In order to compute gradient, we need two points - a tangent has just one (by definition - it just touches the curve)

So the solution is to find a point really close-by and find the gradient of the line that passes through these two points (by the way - this line is called a secant). Then all we have to do is move these points closer and closer together - notice on the activity below that the gradient of the secant will approach the gradient of the tangent. Then, when the distance between the two points is infinitesimal, (we call this idea a limit) the gradient of the secant must equal the gradient of the tangent!
And that's how we find the gradient of a curve!

First Principles

Below is a derivation of the formula for Differentiation from First Principles. It's really just using our formula for gradient: