practicecalculus
Trigonometric integrals

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

\int \tan x\,dx = \ln\lvert\sec x\rvert + C
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
  1. Graph of tan x and its antiderivative
  2. Derivation, step by step
  3. Check by differentiating
  4. Definite integrals
  5. Substitution variants
  6. Worked examples
  7. Common mistakes

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.

\int \tan x\,dx = \ln\lvert\sec x\rvert + C = -\ln\lvert\cos x\rvert + C

Graph of tan x and its antiderivative

Area under y = tan x from 0 to π/4, with the antiderivative y = ln|sec x|
The shaded area is \ln\sqrt{2} \approx 0.347. The dashed antiderivative has a minimum at x = 0, where \tan x = 0, and shoots up near the asymptotes at x = \pm\frac{\pi}{2}.

Derivation, step by step

  1. Rewrite with sine and cosine: \displaystyle\int\tan x\,dx = \int\frac{\sin x}{\cos x}\,dx.
  2. Let u = \cos x. Then du = -\sin x\,dx, so \sin x\,dx = -du.
  3. Substitute: \displaystyle\int\frac{-du}{u} = -\ln\lvert u\rvert + C.
  4. Put u = \cos x back: -\ln\lvert\cos x\rvert + C.
  5. 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

\frac{d}{dx}\ln\lvert\sec x\rvert = \frac{1}{\sec x}\cdot\sec x\tan x = \tan x \checkmark

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

\int_0^{\pi/4}\tan x\,dx = \Big[\ln\lvert\sec x\rvert\Big]_0^{\pi/4} = \ln\sqrt{2} - \ln 1 = \frac{1}{2}\ln 2
\int_0^{\pi/3}\tan x\,dx = \ln\sec\frac{\pi}{3} - 0 = \ln 2

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

\int\tan(ax + b)\,dx = \frac{1}{a}\ln\lvert\sec(ax + b)\rvert + C

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:

\int\tan^3 x\,dx = \int\tan x\sec^2 x\,dx - \int\tan x\,dx = \frac{\tan^2 x}{2} - \ln\lvert\sec x\rvert + C

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

  1. Answering \sec^2 x. That is the derivative of \tan x, not the integral.
  2. Answering \ln\lvert\cos x\rvert without the minus sign. Its derivative is -\tan x.
  3. 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.
  4. 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

Frequently asked questions

What is the integral of tan x?

The integral of \tan x is \ln\lvert\sec x\rvert + C. You will also see it written as -\ln\lvert\cos x\rvert + C.

Are ln|sec x| and -ln|cos x| the same?

Yes. Since \sec x = \frac{1}{\cos x}, \ln\lvert\sec x\rvert = \ln\frac{1}{\lvert\cos x\rvert} = -\ln\lvert\cos x\rvert.

What is the integral of tan x from 0 to π/4?

It is \ln\sec\frac{\pi}{4} - \ln\sec 0 = \ln\sqrt{2} = \frac{1}{2}\ln 2 \approx 0.347.

What is the integral of tan(2x)?

It is \frac{1}{2}\ln\lvert\sec(2x)\rvert + C.

Written by the PracticeCalculus team

We build interactive calculus lessons and write every page to be clear and correct. Spotted something off? Tell us and we will fix it.