You take the derivative $f^\prime$ and find out the points $x$ where it's zero: $f^\prime (x) \stackrel{!}{=} 0$
$f^\prime (x)$ is the slope at $x$. If it's zero it means that you have a found either a minimum, a maximum or a saddle point. You're not interested in saddle points though so you want to check that the points where $f^\prime$ is zero also have the property that $f^{\prime \prime}$ is non-zero. $f^{\prime \prime}$ gives you a measure for the "curvature" of $f$ at that point. Saddle points are horizontal hence have $f^{\prime \prime}$ equal to zero.
Edit As pointed out in the comment by Ronald, $f^{\prime \prime} = 0$ is not a sufficient condition to be at a saddle point. There are functions that satisfy this condition at points where they don't have a saddle point, such as for example $f(x) = x^4$ at $0$. In general you need to look at the first derivative that's non-zero, this is called "higher-order derivative test".
Note that for example if $f$ is a function like $f(x) = x$ then it won't have any points where $f^\prime$ is zero and yet it will attain a maximum at the right end of your interval. To detect this case you simply have to remember to also check $f(a)$ and $f(b)$ if your function is defined on $[a,b]$.
For this you need $f$ to be differentiable. Luckily, your example and probably many of the functions you'll have to find mins and maxs for will be differentiable.