If you've ever searched for the integral of tanx, you've likely seen two different answers: -ln|cosx| + C and ln|secx| + C. Which one is correct? The answer might surprise you—they're both right. This confusion is one of the most common stumbling blocks for calculus students, and it's completely understandable. In this guide, I'll walk you through the proof using u-substitution, explain why those two forms are equivalent, and highlight the mistakes I've seen students make year after year in my own teaching and tutoring work.

What is the Integral of tan x dx? The Core Formula
The integral of tan x dx is one of those results that looks deceptively simple but hides a few subtle details. Here's the fundamental result you need to remember:
∫tanx dx = -ln|cosx| + C = ln|secx| + C This is an indefinite integral, which means we're finding the general antiderivative of tanx. The constant C represents any constant value, since differentiating any constant gives zero.
The Two Equivalent Forms of the Antiderivative of tanx
Let's address the elephant in the room: why do textbooks, websites, and professors sometimes give different-looking answers?
| Form | Expression | When You'll See It |
|---|---|---|
| Form 1 | -ln|cosx| + C | Most common in step-by-step derivations |
| Form 2 | ln|secx| + C | Common in formula tables and quick references |
| The equivalence comes from two simple mathematical facts: |
- Logarithmic property: -ln|a| = ln|a⁻¹| = ln|1/a|
- Reciprocal identity: secx = 1/cosx
So when you have -ln|cosx|, you can rewrite it as ln|(cosx)⁻¹| = ln|1/cosx| = ln|secx|. Both forms are perfectly valid, and neither is "more correct" than the other. In my experience, students who understand why these forms are equivalent rarely make mistakes later. It's the ones who memorize one form without understanding the connection who get tripped up on exams.
Why the Absolute Value Matters in the Result
Here's something I've seen trip up even advanced students: the absolute value bars aren't optional decoration. They matter, and here's why.
The natural logarithm function ln(x) is only defined for positive arguments. But cosx can be negative—for instance, cos(π) = -1. If we wrote the answer as -ln(cosx) without absolute value bars, we'd be claiming the antiderivative doesn't exist for half the domain of tanx. That's simply wrong.
Let me show you a quick numerical example. Consider evaluating our antiderivative at x = π/3:
- With absolute value: -ln|cos(π/3)| = -ln(1/2) = ln(2) ≈ 0.693
- Without absolute value: -ln(cos(π/3)) = -ln(1/2) = ln(2) ≈ 0.693
At this point, they happen to agree because cos(π/3) is positive. But try x = 2π/3:
- With absolute value: -ln|cos(2π/3)| = -ln|-1/2| = -ln(1/2) = ln(2) ≈ 0.693
- Without absolute value: -ln(cos(2π/3)) = -ln(-1/2) — undefined!
The second expression doesn't even exist as a real number. That's why the absolute value is non-negotiable.
How to Integrate tan x Step by Step: The u-Substitution Proof
Now let's get into the actual mechanics. I've taught this to hundreds of students over the years, and the u-substitution approach is by far the cleanest method. Here's how to integrate tan x step by step.
Step 1: Rewrite tanx Using Trigonometric Identities
The key insight is to express tanx in terms of sine and cosine using a basic trigonometric identity:
tanx = sinx / cosx
This gives us:
∫tanx dx = ∫(sinx / cosx) dx
Why do this? Because this form immediately suggests a substitution—the numerator looks like it could be the derivative of the denominator (up to a sign). This is the kind of pattern recognition that becomes second nature with practice.
Step 2: Apply u-Substitution with u = cosx
Here's where the magic happens. Let:
u = cosx
Then differentiate both sides with respect to x:
du = -sinx dx
Notice that our integral has sinx dx in the numerator. We can rearrange the substitution to get:
-du = sinx dx
Now substitute everything into our integral:
∫(sinx / cosx) dx = ∫(1/u)(-du) = -∫(1/u) du
The integral has transformed from something that looks complicated into a basic form. This is exactly what good u-substitution should do—it simplifies the problem into something you already know how to solve.
Step 3: Solve the Simplified Integral and Substitute Back
Now we have a standard result:
-∫(1/u) du = -ln|u| + C The integral of 1/u with respect to u is ln|u|, and we keep the negative sign from our substitution. Now substitute u = cosx back: -ln|cosx| + C And there's our answer. If you prefer the secant form, apply the logarithmic property we discussed earlier:
-ln|cosx| + C = ln|secx| + C One quick note: you might wonder if you could substitute u = sinx instead. Technically, you can, but it leads to a much messier integral involving sec²x. I've seen students try this route, and it almost always ends in frustration. Stick with u = cosx—it's the cleanest path.
Integral of tan^2 x dx and Other Related Trigonometric Integrals
Once you've mastered the integral of tanx, the natural next question is about related integrals. The most common one students ask about is the integral of tan²x.
Solving ∫tan^2 x dx Using the Pythagorean Identity
For this one, we need a different strategy. The Pythagorean identity for tangent and secant is:
tan²x = sec²x - 1
This identity is incredibly useful because it converts a squared tangent into something we can integrate term by term:
∫tan²x dx = ∫(sec²x - 1) dx
Now we integrate each term separately:
∫sec²x dx = tanx + C₁ ∫1 dx = x + C₂
Combining these:
∫tan²x dx = tanx - x + C
This is a result that surprises many students—the integral of tan²x isn't a logarithm at all. It's a combination of tangent and a linear term. This is a good reminder that similar-looking integrals can have very different solutions.
Comparison Table: Integrals of tanx, secx, cotx, and cscx
For quick reference, here's a table of the antiderivatives for the six basic trigonometric functions. I recommend keeping this handy while studying:
| Function | Integral | Notes |
|---|---|---|
| tanx | -ln|cosx| + C = ln|secx| + C | Two equivalent forms |
| secx | ln|secx + tanx| + C | Requires a clever trick to derive |
| cotx | ln|sinx| + C | Analogous to tanx, using u = sinx |
| cscx | -ln|cscx + cotx| + C | Similar structure to secx |
| Notice the pattern: all four of these involve logarithms with absolute values. This isn't a coincidence—it reflects the fact that these functions all have the form (something)/(something else) where the numerator is related to the derivative of the denominator. |
Definite Integral of tanx: From 0 to π/4 and Convergence Issues
So far, we've been working with indefinite integrals. But what happens when we evaluate the definite integral of tanx over specific intervals? This is where things get interesting—and where many students encounter unexpected difficulties.
Evaluating the Definite Integral from 0 to π/4
Let's work through a concrete example: the definite integral of tanx from 0 to π/4.
Using the Fundamental Theorem of Calculus, we evaluate our antiderivative at the upper and lower limits:
∫₀^{π/4} tanx dx = [-ln|cosx|]₀^{π/4} At the upper limit x = π/4:
-ln|cos(π/4)| = -ln(√2/2) At the lower limit x = 0:
-ln|cos(0)| = -ln(1) = 0 Subtracting:
-ln(√2/2) - 0 = -ln(√2/2)
Now, -ln(√2/2) = ln(2/√2) = ln(√2) = (1/2)ln2
So the definite integral from 0 to π/4 equals (1/2)ln2 ≈ 0.3466.
This is a clean, finite result. But not all intervals behave this nicely.
Why the Integral from 0 to π/2 Diverges
Here's a question I get constantly: "Why can't I just evaluate the integral from 0 to π/2 the same way?"
The problem is that tanx has a vertical asymptote at x = π/2. As x approaches π/2 from the left, tanx approaches positive infinity. The function isn't bounded on this interval, so the integral doesn't converge to a finite value.
If you try to evaluate it naively:
∫₀^{π/2} tanx dx = [-ln|cosx|]₀^{π/2} At x = π/2:
-ln|cos(π/2)| = -ln(0) = ∞ The result is infinite, which means the improper integral diverges. This is a crucial distinction: the integral of tanx from 0 to π/4 exists and is finite, but from 0 to π/2 it blows up. Understanding why requires recognizing where the function has singularities.
Practical Applications and Common Mistakes When Integrating tanx
You might be wondering: "When would I actually use this in real life?" It's a fair question. The integral of tanx isn't just an abstract exercise—it shows up in several practical contexts.
Real-World Applications in Physics and Engineering
One of the most common applications I've encountered is in arc length calculations. For instance, if you want to find the length of the curve y = ln|cosx| from x = 0 to x = π/4, you'd need to evaluate:
L = ∫₀^{π/4} √(1 + (dy/dx)²) dx
Since dy/dx = -tanx, this becomes:
L = ∫₀^{π/4} √(1 + tan²x) dx = ∫₀^{π/4} secx dx
And that integral involves the antiderivative of secx, which is closely related to what we've been discussing.
The integral of tanx also appears in signal processing when analyzing certain types of waveforms, and in mechanics when calculating work done by variable forces that follow trigonometric patterns. In my consulting work, I've seen it pop up in unexpected places—from electrical engineering problems involving phase shifts to physics problems about projectile motion with air resistance.
Top 3 Mistakes Students Make and How to Avoid Them
Over years of teaching and tutoring, I've noticed the same mistakes appearing again and again. Here are the top three, with clear wrong-versus-right comparisons:
Mistake 1: Forgetting the Absolute Value
| ❌ Wrong | ✅ Correct |
|---|---|
| ∫tanx dx = -ln(cosx) + C | ∫tanx dx = -ln|cosx| + C |
| This is the most common error I see. Without the absolute value, your answer is undefined for half the domain of tanx. Always include the absolute value bars. |
Mistake 2: Dropping the Constant of Integration
| ❌ Wrong | ✅ Correct |
|---|---|
| ∫tanx dx = -ln|cosx| | ∫tanx dx = -ln|cosx| + C |
| For indefinite integrals, the constant C is non-negotiable. Without it, you're claiming that the antiderivative is unique, which it isn't. Any constant shift is also a valid antiderivative. |
Mistake 3: Confusing the Integral with the Derivative
| ❌ Wrong | ✅ Correct |
|---|---|
| ∫tanx dx = sec²x + C | ∫tanx dx = -ln|cosx| + C |
| This one makes me cringe every time I see it. The derivative of tanx is sec²x, but the integral is a logarithm. These are completely different operations. A quick sanity check: differentiate your answer. If you don't get back tanx, something's wrong. |
Frequently Asked Questions
Is there an antiderivative of tan?
Yes, absolutely. The antiderivative of tanx exists and is -ln|cosx| + C, which is equivalently ln|secx| + C. It's a logarithmic function, which is a perfectly valid elementary function. Some students assume that because tanx isn't one of the basic integration formulas they memorized, it can't be integrated—but that's a misconception. The u-substitution proof we walked through demonstrates that it's not only integrable but actually quite straightforward.
What is the definite integration of TANX?
The definite integral of tanx depends entirely on your limits of integration. For example, the integral from 0 to π/4 equals (1/2)ln2 ≈ 0.3466. However, the integral from 0 to π/2 diverges to infinity because tanx has a vertical asymptote at x = π/2. Always check whether your interval crosses any singularities before attempting to evaluate a definite integral.
Can Tanx be integrated?
Yes, tanx can definitely be integrated. The proof using u-substitution with u = cosx shows this clearly. The misconception that it can't be integrated probably stems from the fact that it's not one of the basic antiderivatives you memorize early on. But with a simple substitution, it becomes a standard logarithmic integral.
How do you apply integral of tanx practically?
One concrete application is calculating the arc length of the curve y = ln|cosx|. The arc length formula requires integrating √(1 + (dy/dx)²), which simplifies to ∫secx dx. The integral of tanx also appears in solving certain differential equations, particularly in physics problems involving oscillatory motion or in engineering contexts where you're analyzing alternating currents.
Conclusion
Let's recap what we've covered. The integral of tanx is:
∫tanx dx = -ln|cosx| + C = ln|secx| + C The proof flows through three clean steps: rewrite tanx as sinx/cosx, apply u-substitution with u = cosx, and integrate to get a logarithmic result. We've also seen that the integral of tan²x is tanx - x + C, and that definite integrals of tanx require careful attention to convergence issues.
The two most important things to remember are the absolute value in the logarithm and the constant of integration C. Get those right, and you're most of the way there.
Ready to test your skills? Try solving ∫tanx dx from 0 to π/3 on your own, and check your answer using an online integral calculator. For more calculus guides, subscribe to our newsletter or download our free trigonometric integrals cheat sheet.





