Skip to content
ihateDesmos

Integral of tan x

Updated 6 November 2026 · Checked numerically by the ihateDesmos engine
The integral of tan x
∫
tan(x)
dx =
−ln(|cos(x)|)+C

The integral of tan x is −ln|cos x| + C, which is the same as ln|sec x| + C. Writing tan x as sin x / cos x reveals a substitution.

−1.0−0.50.51.0−4−2240
Open in calculator
y=tan(x)
in blue and its integral
y=−ln(|cos(x)|)
(with C = 0) in red. Defined for x ≠ π/2 + nπ.

How to integrate tan x

Method: u-substitution.

  1. 1
    Write the integrand as a fraction: tan x = sin x / cos x.
  2. 2
    Let u = cos x, so du = −sin x dx.
  3. 3
    The integral becomes −∫(1/u) du = −ln|u|.
  4. 4
    Substitute back: −ln|cos x| + C.
  5. 5
    Using log rules, −ln|cos x| = ln|1/cos x| = ln|sec x|.

What it means

Near the asymptotes at ±π/2, tan x blows up, and so does its integral, since cos x approaches 0. The integral has its minimum at x = 0, where tan x changes sign.

The integral from 0 to π/4

Using the antiderivative: F(π/4) − F(0) = (ln 2)/2, which is about ln 2/2. A direct numerical integration of tan x gives ln 2/2, which agrees.

−1.5−1−0.50.511.5−5−4−3−2−112345

Check by differentiating

The derivative of the answer should give back the original function. The last column measures that slope directly from the answer, and it matches.

Checking the integral
xtan xSlope of the answer
−1−1.55741−1.55741
−π/4−1−1
000
π/411
11.557411.55741

Common mistakes

  • Writing sec²x, which is the derivative of tan x, not its integral.
  • Leaving out the absolute value, which fails where cos x is negative.

Frequently asked questions

What is the integral of tan x?
The integral of tan x is −ln|cos x| + C, for x ≠ π/2 + nπ.
What is the integral of tan x from 0 to π/4?
(ln 2)/2, which is about ln 2/2.
Are −ln|cos x| and ln|sec x| the same?
Yes. Since sec x = 1/cos x, the log rules make them equal. Either answer is correct.

Keep going

Integrate any function

Type your own function into the integral calculator for the steps, the answer and a graph.

Open the integral calculator