Integral of tan x: Formula, Derivation and Examples
The integral of tan x is ln|sec x| + C, or -ln|cos x| + C. See the u-substitution with u = cos x, why both forms agree, and worked definite integrals.
Trigonometric integrals Updated 2 min read
At a glance
- Antiderivative
- \ln\lvert\sec x\rvert + C
- Equivalent form
- -\ln\lvert\cos x\rvert + C
- Method
- Rewrite as \dfrac{\sin x}{\cos x}, then u = \cos x
- Linear form
- \int\tan(ax)\,dx = \dfrac{1}{a}\ln\lvert\sec(ax)\rvert + C
- Check
- \dfrac{d}{dx}\ln\lvert\sec x\rvert = \tan x
On this page
The integral of \tan x is \ln\lvert\sec x\rvert + C. There is no basic derivative that gives \tan x directly, so the answer comes from a quick substitution.
Graph of tan x and its antiderivative
Derivation, step by step
- Rewrite with sine and cosine: \displaystyle\int\tan x\,dx = \int\frac{\sin x}{\cos x}\,dx.
- Let u = \cos x. Then du = -\sin x\,dx, so \sin x\,dx = -du.
- Substitute: \displaystyle\int\frac{-du}{u} = -\ln\lvert u\rvert + C.
- Put u = \cos x back: -\ln\lvert\cos x\rvert + C.
- Use a log rule to tidy up: -\ln\lvert\cos x\rvert = \ln\frac{1}{\lvert\cos x\rvert} = \ln\lvert\sec x\rvert.
Step 3 uses the integral of 1/x. This is the pattern \int\frac{f'}{f}\,dx = \ln\lvert f\rvert, with a minus sign because the top is -f'.
Check by differentiating
This uses the derivative of sec x, \sec x\tan x. Compare with the derivative of tan x, which is \sec^2 x: a completely different result.
Definite integrals
Since \tan x is odd, \int_{-a}^{a}\tan x\,dx = 0 for a < \frac{\pi}{2}. Integrating up to \frac{\pi}{2} is improper and diverges, because \ln\sec x \to \infty.
Substitution variants
For example, \int\tan(3x)\,dx = \frac{1}{3}\ln\lvert\sec(3x)\rvert + C.
With a matching inside derivative: \int x\tan(x^2)\,dx = \frac{1}{2}\ln\lvert\sec(x^2)\rvert + C.
Worked examples
Example 1: tan times sec². \int\tan x\sec^2 x\,dx with u = \tan x, du = \sec^2 x\,dx, gives \frac{\tan^2 x}{2} + C.
Example 2: tan cubed. Use \tan^2 x = \sec^2 x - 1:
Example 3: the cot partner. The same steps with u = \sin x give \int\cot x\,dx = \ln\lvert\sin x\rvert + C. See the integral of cot x.
Common mistakes
- Answering \sec^2 x. That is the derivative of \tan x, not the integral.
- Answering \ln\lvert\cos x\rvert without the minus sign. Its derivative is -\tan x.
- Dropping the absolute value. \cos x is negative on \left(\frac{\pi}{2}, \frac{3\pi}{2}\right), and \ln of a negative number is undefined.
- Mixing it up with \int\tan^2 x\,dx, which is \tan x - x + C. See the integral of tan² x.
Practise with u-substitution problems.
Practice it now
U-substitution
Solve real problems on this topic with instant feedback, hints and a step-by-step walkthrough for every answer. Free, no sign-up needed to start.
Practice this lesson