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.
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.
- 1Write the integrand as a fraction: tan x = sin x / cos x.
- 2Let u = cos x, so du = −sin x dx.
- 3The integral becomes −∫(1/u) du = −ln|u|.
- 4Substitute back: −ln|cos x| + C.
- 5Using 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.
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.
| x | tan x | Slope of the answer |
|---|---|---|
| −1 | −1.55741 | −1.55741 |
| −π/4 | −1 | −1 |
| 0 | 0 | 0 |
| π/4 | 1 | 1 |
| 1 | 1.55741 | 1.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.