Integrals

Integral of sec(x): ln|sec x + tan x| + C, Step by Step

Integral of sec(x): ln|sec x + tan x| + C, Step by Step — CalculusCalc cover image

Quick answer:

$$\int\sec x\,dx = \ln\left|\sec x + \tan x\right| + C$$

The integral of sec x is famous for looking impossible until you see one clever step. This guide explains why that step works, derives the formula two ways, shows the equivalent forms you’ll see in other books, and then works through seven examples, including the exam favorite \( \int\sec^3 x\,dx \).

Why it works: sec x is a log-derivative

Recall the log rule: if the numerator of a fraction is the derivative of its denominator, the integral is a logarithm. So the question is whether \( \sec x \) can be written as \( \frac{g'(x)}{g(x)} \) for some function \( g \).

It can. Differentiate \( g(x) = \sec x + \tan x \):

$$g'(x) = \sec x\tan x + \sec^2 x = \sec x\,(\sec x + \tan x)$$

The derivative is the original function times \( \sec x \). Divide both sides by \( g(x) \) and you get \( \frac{g'(x)}{g(x)} = \sec x \). That single observation is the whole proof. The famous “trick” below is just a way of discovering it on paper.

For a picture, think about the graph on \( [0, \frac{\pi}{2}) \). Secant starts at 1 when \( x = 0 \) and climbs to a vertical asymptote at \( \frac{\pi}{2} \). The area under it starts slowly, because \( \sec x \) is close to 1 near zero, and then grows without bound as the curve shoots upward. The antiderivative \( \ln(\sec x + \tan x) \) behaves the same way: it’s 0 at \( x = 0 \), increases steadily, and heads to infinity as the argument of the log blows up.

The famous trick

Multiply and divide by \( \sec x + \tan x \):

$$\begin{aligned} \int\sec x\,dx &= \int\frac{\sec x(\sec x + \tan x)}{\sec x + \tan x}\,dx \\ &= \int\frac{\sec^2 x + \sec x\tan x}{\sec x + \tan x}\,dx \end{aligned}$$

Now look at the denominator \( u = \sec x + \tan x \). Its derivative is

$$du = \left(\sec x\tan x + \sec^2 x\right)dx$$

which is exactly the numerator. So the integral becomes \( \int\frac{du}{u} = \ln|u| + C \):

$$\int\sec x\,dx = \ln|\sec x + \tan x| + C$$

It looks like magic, but it’s just u-substitution with a well-chosen \( u \).

Method 2: rewrite with cosine

\( \sec x = \frac{\cos x}{\cos^2 x} = \frac{\cos x}{1 - \sin^2 x} \). With \( u = \sin x \), \( du = \cos x\,dx \):

$$\begin{aligned} \int\frac{du}{1 - u^2} &= \frac12\ln\left|\frac{1 + u}{1 - u}\right| + C \\ &= \frac12\ln\left|\frac{1+\sin x}{1-\sin x}\right| + C \end{aligned}$$

using partial fractions. To see that this equals \( \ln|\sec x + \tan x| \), multiply the top and bottom of the fraction by \( 1 + \sin x \):

$$\frac{1+\sin x}{1-\sin x} = \frac{(1+\sin x)^2}{\cos^2 x} = (\sec x + \tan x)^2$$

Half the log of a square is the log of the absolute value, so the two answers match exactly.

Equivalent forms you might see

Different books print different versions. All of these are correct antiderivatives of \( \sec x \):

  • \( \ln|\sec x + \tan x| + C \), the standard form
  • \( -\ln|\sec x - \tan x| + C \), because \( (\sec x + \tan x)(\sec x - \tan x) = 1 \)
  • \( \ln\left|\tan\left(\frac x2 + \frac\pi4\right)\right| + C \), the historical form from navigation tables

If your answer doesn’t match the back of the book, differentiate it. If you get \( \sec x \), you’re right.

Check by differentiating

$$\begin{aligned} \frac{d}{dx}\ln|\sec x + \tan x| &= \frac{\sec x\tan x + \sec^2 x}{\sec x + \tan x} \\ &= \frac{\sec x(\tan x + \sec x)}{\sec x + \tan x} = \sec x \checkmark \end{aligned}$$

Worked examples

Example 1 (basic definite). Evaluate from 0 to \( \frac{\pi}{4} \). At \( \frac{\pi}{4} \), \( \sec = \sqrt2 \) and \( \tan = 1 \); at 0, \( \sec = 1 \) and \( \tan = 0 \):

$$\int_0^{\pi/4}\sec x\,dx = \ln\left(\sqrt2 + 1\right) - \ln 1 = \ln\left(1 + \sqrt2\right) \approx 0.8814$$

Example 2 (linear inside). For \( \int\sec(4x)\,dx \), let \( u = 4x \), so \( dx = \frac{du}{4} \). The result is one quarter of the basic formula, because squeezing the graph horizontally by a factor of 4 shrinks every area by the same factor:

$$\int\sec(4x)\,dx = \frac14\ln|\sec 4x + \tan 4x| + C$$

Example 3 (symmetric interval). Secant is even, so the area from \( -\frac{\pi}{4} \) to \( \frac{\pi}{4} \) is twice the area from 0 to \( \frac{\pi}{4} \). That gives \( 2\ln(1 + \sqrt2) \approx 1.7627 \) with no extra work. Secant is even because cosine is even: \( \sec(-x) = \frac{1}{\cos(-x)} = \sec x \). Whenever you integrate an even function over an interval centered at 0, you can double the right half, which usually means evaluating at 0, where everything is simple.

Example 4 (clean exact value). At \( \frac{\pi}{6} \), \( \sec = \frac{2}{\sqrt3} \) and \( \tan = \frac{1}{\sqrt3} \). Their sum is \( \frac{3}{\sqrt3} = \sqrt3 \), so

$$\int_0^{\pi/6}\sec x\,dx = \ln\sqrt3 = \frac{\ln 3}{2} \approx 0.5493$$

Example 5 (substitution first). For \( \int x\sec(x^2)\,dx \), the derivative of the inside, \( 2x \), is present up to a factor of 2. Let \( u = x^2 \), so \( x\,dx = \frac{du}{2} \):

$$\int x\sec(x^2)\,dx = \frac12\ln\left|\sec(x^2) + \tan(x^2)\right| + C$$

Example 6 (split the fraction). For \( \int\frac{1 + \sin x}{\cos x}\,dx \), split into \( \sec x + \tan x \) and integrate each piece. The second piece is the integral of tan x:

$$\int\frac{1+\sin x}{\cos x}\,dx = \ln|\sec x + \tan x| + \ln|\sec x| + C$$

Example 7 (exam level: sec³x). Use integration by parts with \( u = \sec x \) and \( dv = \sec^2 x\,dx \), so \( du = \sec x\tan x\,dx \) and \( v = \tan x \). Call the integral \( I \):

$$\begin{aligned} I &= \sec x\tan x - \int\sec x\tan^2 x\,dx \\ &= \sec x\tan x - \int\sec x(\sec^2 x - 1)\,dx \\ &= \sec x\tan x - I + \int\sec x\,dx \end{aligned}$$

The original integral reappeared on the right. Instead of going in circles, treat \( I \) as an unknown in an equation. Add \( I \) to both sides and divide by 2:

$$\int\sec^3 x\,dx = \frac12\left(\sec x\tan x + \ln|\sec x + \tan x|\right) + C$$

You can confirm any of these with the integral calculator.

The csc x version

Cosecant works the same way with the signs flipped. The derivative of \( \csc x + \cot x \) is \( -\csc x\cot x - \csc^2 x \), which equals \( -\csc x(\csc x + \cot x) \). So \( \csc x \) is the log-derivative of \( \csc x + \cot x \) with a minus sign, and

$$\int\csc x\,dx = -\ln|\csc x + \cot x| + C$$

An equivalent form you’ll also see is \( \ln|\csc x - \cot x| + C \), since the product \( (\csc x + \cot x)(\csc x - \cot x) \) equals 1.

A strategy for other secant integrals

The integral of sec x is the base case for a whole family. When you face a product of powers of secant and tangent, sort it like this:

  • Even power of secant: save a \( \sec^2 x \), convert the rest to tangents with \( \sec^2 x = 1 + \tan^2 x \), and let \( u = \tan x \).
  • Odd power of tangent: save a \( \sec x\tan x \), convert the remaining tangents to secants, and let \( u = \sec x \).
  • Odd power of secant alone: use integration by parts, as in Example 7. Each round lowers the power by 2 until you land on the plain \( \int\sec x\,dx \).

That last case is why this formula matters so much: every odd power of secant eventually reduces to it.

Companion results

Integral Result
\( \int\csc x\,dx \) \( -\ln\lvert\csc x + \cot x\rvert + C \)
\( \int\sec x\tan x\,dx \) \( \sec x + C \)
\( \int\sec^2 x\,dx \) \( \tan x + C \)
\( \int\sec(ax)\,dx \) \( \frac1a\ln\lvert\sec ax + \tan ax\rvert + C \)

Common mistakes

  1. Writing \( \sec x\tan x \). That’s the derivative of \( \sec x \), so it goes the wrong direction.
  2. Writing \( \ln|\sec x| + C \). That’s the integral of \( \tan x \). Its derivative is \( \tan x \), not \( \sec x \).
  3. Treating \( \frac{1}{\cos x} \) like \( \frac1x \). The answer is not \( \ln|\cos x| \); the log rule needs the derivative of the denominator on top, and the derivative of \( \cos x \) is not 1.
  4. Forgetting the \( \frac1a \) factor. For \( \sec(ax) \), divide by \( a \).
  5. Integrating across an asymptote. Secant blows up at odd multiples of \( \frac{\pi}{2} \). An integral like the one from 0 to \( \pi \) diverges.

Where it’s used

Arc length. The curve \( y = \ln(\cos x) \) has slope \( -\tan x \), so \( \sqrt{1 + (y')^2} = \sec x \) on \( (-\frac{\pi}{2}, \frac{\pi}{2}) \). Its arc length from 0 to \( \frac{\pi}{4} \) is therefore \( \ln(1 + \sqrt2) \), the same number as Example 1.

Trig substitution. With \( x = \tan\theta \), the integral \( \int\frac{dx}{\sqrt{1 + x^2}} \) turns into \( \int\sec\theta\,d\theta \), which gives \( \ln\left(x + \sqrt{1 + x^2}\right) + C \). The same move appears across trig substitution problems, whenever a root of the form \( \sqrt{1 + x^2} \) or \( \sqrt{x^2 - 1} \) shows up.

Maps. On a Mercator map, the vertical distance from the equator to latitude \( \varphi \) is proportional to the integral of \( \sec \) from 0 to \( \varphi \). That is why this integral was tabulated before calculus textbooks gave it a formula.

Try it yourself

Step-by-step solverExact symbolic engine

Interactive Calculus Problem Solver

Derivatives, antiderivatives, definite and improper integrals, and limits. Every answer comes with the rules used, and antiderivatives are verified by differentiating them back.

Try:
Input syntax
  • Powers x^2, roots sqrt(x), cbrt(x), absolute value |x|
  • Implicit multiplication works: 3x sin(2x)
  • sin cos tan sec csc cot, asin acos atan, sinh cosh tanh
  • e^x or exp(x); ln(x) and log(x) are both the natural log
  • Constants pi and e; bounds accept inf and -inf
Enter a function and press Solve to see a full worked solution.

Practice problems

Try these before checking the answers.

  1. \( \int\sec(3x)\,dx \)
  2. \( \int_0^{\pi/3}\sec x\,dx \)
  3. \( \int\sec x\,(\sec x + \tan x)\,dx \)
  4. \( \int\sec\frac{x}{3}\,dx \)
  5. \( \int_0^{\pi/6}\sec(2x)\,dx \)
  6. \( \int\frac{dx}{\sqrt{1 + x^2}} \)

Answers: (1) \( \frac13\ln|\sec 3x + \tan 3x| + C \); (2) \( \ln\left(2 + \sqrt3\right) \); (3) \( \tan x + \sec x + C \); (4) \( 3\ln\left|\sec\frac x3 + \tan\frac x3\right| + C \); (5) \( \frac12\ln\left(2 + \sqrt3\right) \); (6) \( \ln\left(x + \sqrt{1 + x^2}\right) + C \).

FAQ

Is the integral of sec x equal to sec x tan x?

No, that’s the derivative of \( \sec x \). See derivative of sec x.

Where does this integral appear?

In the Mercator map projection, in arc length problems, and in trig substitution integrals.

How would I know to multiply by sec x + tan x?

You aren’t expected to invent it on the spot. Remember the reason instead: the derivative of \( \sec x + \tan x \) is \( \sec x \) times itself, which makes \( \sec x \) its log-derivative.

What is the integral of sec x from 0 to π/2?

It diverges. As \( x \) approaches \( \frac{\pi}{2} \), both \( \sec x \) and \( \tan x \) grow without bound, so the log does too.

What is the integral of sec³x?

\( \frac12\left(\sec x\tan x + \ln|\sec x + \tan x|\right) + C \), found with integration by parts as in Example 7.

What is the integral of csc x?

It’s \( -\ln|\csc x + \cot x| + C \), found with the same multiply-and-divide trick using \( \csc x + \cot x \).

Related: integral of tan x, integral of sec²x.

Further reading

Calculators for this topic

Leave a comment

Your email address will not be published. Required fields are marked *