# Integral of tan² x: Formula, Derivation and Examples

> The integral of tan² x is tan x - x + C. See how the identity tan² x = sec² x - 1 does all the work, plus tan²(ax), tan³ x and definite integral examples.

Source: https://practicecalculus.com/integrals/tan-squared-x
Updated: 2026-11-06

$$ \int \tan^2 x\,dx = \tan x - x + C $$

## At a glance

- **Antiderivative:** $\tan x - x + C$
- **Identity used:** $\tan^2 x = \sec^2 x - 1$
- **From 0 to π/4:** $1 - \dfrac{\pi}{4} \approx 0.215$
- **Linear form:** $\int\tan^2(ax)\,dx = \dfrac{\tan(ax)}{a} - x + C$
- **Cotangent partner:** $\int\cot^2 x\,dx = -\cot x - x + C$

## Key takeaways

- The integral of $\tan^2 x$ is $\tan x - x + C$.
- Rewrite with the Pythagorean identity $\tan^2 x = \sec^2 x - 1$, then integrate each term.
- Do not use the power rule. $\frac{\tan^3 x}{3}$ is wrong.
- The same identity unlocks odd powers like $\tan^3 x$.

The **integral of $\tan^2 x$ is $\tan x - x + C$**. One identity turns it into two integrals you already know.

$$\int \tan^2 x\,dx = \tan x - x + C$$

## Graph of tan² x and its antiderivative

```graph
title: 'Area under y = tan² x from 0 to π/4, with the antiderivative y = tan x - x'
caption: 'The shaded area is $1 - \frac{\pi}{4} \approx 0.215$. The dashed antiderivative is flat at the origin, because $\tan^2 0 = 0$, and never decreases.'
x: [-1.6, 1.6]
y: [-2.5, 4]
functions:
  - expr: tan(x)^2
    label: y = tan² x
    domain: [-1.1, 1.1]
  - expr: tan(x) - x
    label: y = tan x - x (antiderivative)
    dashed: true
    domain: [-1.4, 1.4]
shade: {expr: tan(x)^2, from: 0, to: 0.7854}
points:
  - [0.7854, 1, '(π/4, 1)']
```

## Derivation, step by step

1. Start from the Pythagorean identity $\sin^2 x + \cos^2 x = 1$. Divide by $\cos^2 x$ to get $\tan^2 x + 1 = \sec^2 x$.
2. Rearrange: $\tan^2 x = \sec^2 x - 1$.
3. Substitute: $\displaystyle\int\tan^2 x\,dx = \int\sec^2 x\,dx - \int 1\,dx$.
4. Use the [integral of sec² x](/integrals/sec-squared-x), $\tan x$, and the [integral of a constant](/integrals/constant), $x$.
5. Combine: $\tan x - x + C$.

## Check by differentiating

$$\frac{d}{dx}(\tan x - x) = \sec^2 x - 1 = \tan^2 x \checkmark$$

## Definite integrals

$$\int_0^{\pi/4}\tan^2 x\,dx = \left(\tan\frac{\pi}{4} - \frac{\pi}{4}\right) - 0 = 1 - \frac{\pi}{4} \approx 0.215$$

$$\int_0^{\pi/3}\tan^2 x\,dx = \sqrt{3} - \frac{\pi}{3} \approx 0.685$$

Since $\tan^2 x$ is even, $\int_{-\pi/4}^{\pi/4}\tan^2 x\,dx = 2 - \frac{\pi}{2}$.

## Substitution variants

$$\int\tan^2(ax + b)\,dx = \frac{1}{a}\tan(ax + b) - x + C$$

Note that only the $\tan$ term gets the factor $\frac{1}{a}$. The $-x$ comes from integrating the constant $1$, which has no inside function.

**Example 1.** $\int\tan^2(3x)\,dx = \frac{1}{3}\tan(3x) - x + C$.

**Example 2.** $\int\tan^2\frac{x}{2}\,dx = 2\tan\frac{x}{2} - x + C$.

## Higher powers of tan

The identity $\tan^2 x = \sec^2 x - 1$ is the key to every power of $\tan x$.

**Example 3: tan³ x.**

$$\int\tan^3 x\,dx = \int\tan x(\sec^2 x - 1)\,dx = \int\tan x\sec^2 x\,dx - \int\tan x\,dx$$

The first piece is $\frac{\tan^2 x}{2}$ with $u = \tan x$. The second is the [integral of tan x](/integrals/tan-x). So

$$\int\tan^3 x\,dx = \frac{\tan^2 x}{2} - \ln\lvert\sec x\rvert + C$$

**Example 4: tan² x sec² x.** Here $u = \tan x$ works directly: $\int\tan^2 x\sec^2 x\,dx = \frac{\tan^3 x}{3} + C$. This is the one case where $\frac{\tan^3 x}{3}$ is the right answer, because the $\sec^2 x$ factor is present.

**Example 5: tan⁴ x.** $\tan^4 x = \tan^2 x(\sec^2 x - 1) = \tan^2 x\sec^2 x - \tan^2 x$, so

$$\int\tan^4 x\,dx = \frac{\tan^3 x}{3} - \tan x + x + C$$

## Common mistakes

1. **Answering $\frac{\tan^3 x}{3}$.** That needs a $\sec^2 x$ factor. Check: its derivative is $\tan^2 x\sec^2 x$.
2. **Answering $\sec^2 x$ or $\ln^2\lvert\sec x\rvert$.** Neither differentiates back to $\tan^2 x$.
3. **Getting the identity backwards.** It is $\sec^2 x - 1$, not $1 - \sec^2 x$. Test at $x = \frac{\pi}{4}$: $\tan^2 = 1$ and $\sec^2 - 1 = 2 - 1 = 1$.
4. **Dividing $-x$ by $a$** in $\int\tan^2(ax)\,dx$.

Practise on [trig integral problems](/practice-problems/trig-integrals).

## Frequently asked questions

### What is the integral of tan² x?

It is $\tan x - x + C$.

### What is the integral of tan² x from 0 to π/4?

It is $\left(1 - \frac{\pi}{4}\right) - 0 = 1 - \frac{\pi}{4} \approx 0.215$.

### What is the integral of tan²(2x)?

It is $\frac{1}{2}\tan(2x) - x + C$.

### What is the integral of tan³ x?

Write $\tan^3 x = \tan x\sec^2 x - \tan x$. The answer is $\frac{\tan^2 x}{2} - \ln\lvert\sec x\rvert + C$.
