AP Calculus AB and BC

Integral of tan x: Answer, Derivation, and Mistakes

The integral of tan x is -ln|cos x| + C, which is also written ln|sec x| + C. Rewrite tan x as sin x over cos x, then substitute u = cos x, so du = -sin x dx and the integral becomes -du/u. Keep the absolute value: cos x is negative on part of every period, so ln(cos x) alone is undefined there.

∫tan⁡x dx=−ln⁡∣cos⁡x∣+C\int \tan x\,dx = -\ln\left|\cos x\right| + C

How to integrate tan x with u-substitution

tan⁡x\tan x is not one of the basic antiderivatives you memorize, so the first move is to rewrite it in terms of sine and cosine.

∫tan⁡x dx=∫sin⁡xcos⁡x dx\int \tan x\,dx = \int \frac{\sin x}{\cos x}\,dx

Now the numerator is the derivative of the denominator up to a sign, which is the signal for u-substitution (Topic 6.9). Let u=cos⁡xu = \cos x.

u=cos⁡x,du=−sin⁡x dx,sin⁡x dx=−duu = \cos x, \qquad du = -\sin x\,dx, \qquad \sin x\,dx = -du

Substituting turns the whole integral into the one antiderivative you already know, ∫duu\int \frac{du}{u}, with a minus sign out front.

∫sin⁡xcos⁡x dx=∫−duu=−∫duu\int \frac{\sin x}{\cos x}\,dx = \int \frac{-du}{u} = -\int \frac{du}{u}

Integrate, then substitute u=cos⁡xu = \cos x back in.

−∫duu=−ln⁡∣u∣+C=−ln⁡∣cos⁡x∣+C-\int \frac{du}{u} = -\ln\left|u\right| + C = -\ln\left|\cos x\right| + C

Keep the absolute value

cos⁡x\cos x is negative on half of every period, and the logarithm of a negative number is undefined. Writing −ln⁡(cos⁡x)-\ln(\cos x) instead of −ln⁡∣cos⁡x∣-\ln\left|\cos x\right| silently restricts the answer to intervals where cos⁡x>0\cos x > 0, such as −π2<x<π2-\frac{\pi}{2} < x < \frac{\pi}{2}.

Why -ln|cos x| and ln|sec x| are the same answer

Textbooks and scoring guidelines print both forms. They are identical, because a leading minus sign on a logarithm is an exponent of −1-1 on the inside.

−ln⁡∣cos⁡x∣=ln⁡∣cos⁡x∣−1=ln⁡∣1cos⁡x∣=ln⁡∣sec⁡x∣-\ln\left|\cos x\right| = \ln\left|\cos x\right|^{-1} = \ln\left|\frac{1}{\cos x}\right| = \ln\left|\sec x\right|

Use whichever form you find easier to differentiate back. Both are correct on the AP exam, and neither is preferred, so do not waste time converting between them.

To check the answer, differentiate it. The chain rule on ln⁡∣cos⁡x∣\ln\left|\cos x\right| gives the derivative of the inside over the inside.

ddx[−ln⁡∣cos⁡x∣]=−1cos⁡x⋅(−sin⁡x)=sin⁡xcos⁡x=tan⁡x\frac{d}{dx}\left[-\ln\left|\cos x\right|\right] = -\frac{1}{\cos x} \cdot (-\sin x) = \frac{\sin x}{\cos x} = \tan x

A worked definite integral

Once you have the antiderivative, definite integrals follow from the Fundamental Theorem of Calculus (Topic 6.7). Evaluate ∫0π/3tan⁡x dx\int_0^{\pi/3} \tan x\,dx.

∫0π/3tan⁡x dx=[−ln⁡∣cos⁡x∣]0π/3\int_0^{\pi/3} \tan x\,dx = \left[-\ln\left|\cos x\right|\right]_0^{\pi/3}

At the upper limit cos⁡π3=12\cos\frac{\pi}{3} = \frac{1}{2}, and at the lower limit cos⁡0=1\cos 0 = 1, so the second term vanishes.

−ln⁡∣cos⁡π3∣+ln⁡∣cos⁡0∣=−ln⁡12+ln⁡1=ln⁡2-\ln\left|\cos\frac{\pi}{3}\right| + \ln\left|\cos 0\right| = -\ln\frac{1}{2} + \ln 1 = \ln 2

Check the interval first

tan⁡x\tan x has vertical asymptotes at x=π2+kπx = \frac{\pi}{2} + k\pi. An interval such as [0,π][0, \pi] contains one, so ∫0πtan⁡x dx\int_0^{\pi} \tan x\,dx is improper and the plug-in-the-limits computation is meaningless. Confirm the interval avoids every asymptote before you evaluate.

Where the integral of tan x shows up on the AP exam

This integral belongs to Unit 6, Integration and Accumulation of Change, which carries a weighting of 15 to 20 percent on both AB and BC. It is a standard example for Topic 6.9, Integrating Using Substitution, and it reappears in Topic 6.14, Selecting Techniques for Antidifferentiation, as the case where an integrand that looks like a trig function is really a 1u\frac{1}{u} integral in disguise.

  • Topic 6.9, Integrating Using Substitution: the derivation itself, with u=cos⁡xu = \cos x
  • Topic 6.14, Selecting Techniques for Antidifferentiation: recognizing tan⁡x\tan x as a u′u\frac{u'}{u} pattern rather than a memorized form
  • Topic 6.7, the Fundamental Theorem of Calculus and Definite Integrals: evaluating ∫abtan⁡x dx\int_a^b \tan x\,dx on an interval free of asymptotes
  • Unit 7, separable differential equations: ∫tan⁡x dx\int \tan x\,dx appears after you separate variables and integrate both sides

The companion result comes from the same substitution run on the reciprocal pairing, with u=sin⁡xu = \sin x and no minus sign to carry.

∫cot⁡x dx=ln⁡∣sin⁡x∣+C\int \cot x\,dx = \ln\left|\sin x\right| + C

Common mistakes with the integral of tan x

  • Dropping the absolute value and writing −ln⁡(cos⁡x)+C-\ln(\cos x) + C. That answer is only valid where cos⁡x>0\cos x > 0, and graders read the bars.
  • Losing the minus sign. Since du=−sin⁡x dxdu = -\sin x\,dx, the numerator contributes −du-du, and forgetting it flips the sign of the whole answer.
  • Answering sec⁡2x\sec^2 x. That is ddx[tan⁡x]\frac{d}{dx}[\tan x], the derivative, not the antiderivative.
  • Reaching for integration by parts. There is no product to split here, and the substitution finishes in one line.
  • Omitting +C+ C on an indefinite integral, which costs a point on free response.

The pattern behind the answer

Any integrand of the form u′u\frac{u'}{u} integrates to ln⁡∣u∣+C\ln|u| + C. tan⁡x=sin⁡xcos⁡x\tan x = \frac{\sin x}{\cos x} fits it once you notice that sin⁡x\sin x is the negative of the derivative of cos⁡x\cos x. Training yourself to spot that pattern is worth more than memorizing this single result.

Every answer on this page is machine checked

An automated test differentiates the antiderivative above and confirms it returns the integrand. A wrong sign or a missing factor fails the build, so it cannot reach you.

Frequently asked questions

What is the integral of tan x?

∫tan⁡x dx=−ln⁡∣cos⁡x∣+C\int \tan x\,dx = -\ln\left|\cos x\right| + C, equivalently ln⁡∣sec⁡x∣+C\ln\left|\sec x\right| + C. Both forms are accepted on the AP exam.

Why does the integral of tan x need an absolute value?

Because the substitution ends at ∫duu\int \frac{du}{u}, whose antiderivative is ln⁡∣u∣+C\ln|u| + C for every u≠0u \neq 0, not just positive uu. Here u=cos⁡xu = \cos x, which is negative on half of every period, so −ln⁡(cos⁡x)-\ln(\cos x) would be undefined on those intervals while −ln⁡∣cos⁡x∣-\ln\left|\cos x\right| is valid between consecutive asymptotes.

Is -ln|cos x| the same as ln|sec x|?

Yes. Moving the minus sign inside makes it ln⁡∣cos⁡x∣−1=ln⁡∣1cos⁡x∣=ln⁡∣sec⁡x∣\ln\left|\cos x\right|^{-1} = \ln\left|\frac{1}{\cos x}\right| = \ln\left|\sec x\right|. The two answers differ only in appearance, not in value.

What is the integral of cot x?

∫cot⁡x dx=ln⁡∣sin⁡x∣+C\int \cot x\,dx = \ln\left|\sin x\right| + C. Rewrite cot⁡x=cos⁡xsin⁡x\cot x = \frac{\cos x}{\sin x} and substitute u=sin⁡xu = \sin x, so du=cos⁡x dxdu = \cos x\,dx and no minus sign appears.

Can I evaluate the definite integral of tan x from 0 to pi?

No. tan⁡x\tan x has a vertical asymptote at x=π2x = \frac{\pi}{2}, which lies inside [0,π][0, \pi], so the integral is improper and diverges. Mechanically substituting the limits into −ln⁡∣cos⁡x∣-\ln\left|\cos x\right| produces a number, but that number means nothing. Always check for asymptotes inside the interval first.