# Derivative of tan x: Formula, Proof and Examples

> The derivative of tan x is sec²x. See the quotient rule proof, the 1 + tan²x form, the chain rule for tan(u) and examples like tan(4x) and tan²x.

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

$$ \frac{d}{dx}\,\tan x = \sec^2 x $$

## At a glance

- **Derivative:** $\sec^2 x$ for $x \ne \frac{\pi}{2} + k\pi$
- **Other forms:** $\dfrac{1}{\cos^2 x} = 1 + \tan^2 x$
- **Chain rule form:** $\dfrac{d}{dx}\tan u = \sec^2 u \cdot u'$
- **Slope at x = 0:** $\sec^2 0 = 1$
- **Integral version:** $\int \sec^2 x\,dx = \tan x + C$

## Key takeaways

- The derivative of $\tan x$ is $\sec^2 x$, which also equals $1 + \tan^2 x$.
- It comes from the quotient rule on $\frac{\sin x}{\cos x}$ and the identity $\sin^2 x + \cos^2 x = 1$.
- Since $\sec^2 x \ge 1$, $\tan x$ is increasing on every interval where it is defined.
- With the chain rule, $\frac{d}{dx}\tan u = \sec^2 u \cdot u'$.

The **derivative of $\tan x$ is $\sec^2 x$**. You will also see it written $\frac{1}{\cos^2 x}$ or $1 + \tan^2 x$. All three are the same function.

$$\frac{d}{dx}\,\tan x = \sec^2 x$$

## Graph of tan x and its derivative

```graph
title: 'Graph of y = tan x and its derivative y = sec²x'
caption: 'One branch of $\tan x$ between its asymptotes. The slope is smallest at $x = 0$, where it equals $1$, and grows without bound near $\pm\frac{\pi}{2}$.'
x: [-1.6, 1.6]
y: [-6, 8]
functions:
  - expr: tan(x)
    label: y = tan x
    domain: [-1.4, 1.4]
  - expr: sec(x)^2
    label: y = sec²x (derivative)
    dashed: true
    domain: [-1.2, 1.2]
vertical:
  - x: 1.5708
    label: x = π/2
  - x: -1.5708
    label: x = -π/2
points:
  - [0, 0, 'slope 1']
```

Because $\sec^2 x$ is never below $1$, the tangent function is always increasing between asymptotes. It never has a horizontal tangent.

## Proof with the quotient rule

Write $\tan x = \frac{\sin x}{\cos x}$ and use the [quotient rule](/rules/quotient-rule):

$$\frac{d}{dx}\tan x = \frac{\cos x\cdot\cos x - \sin x\cdot(-\sin x)}{\cos^2 x} = \frac{\cos^2 x + \sin^2 x}{\cos^2 x}$$

The Pythagorean identity turns the top into $1$:

$$\frac{d}{dx}\tan x = \frac{1}{\cos^2 x} = \sec^2 x$$

If instead you split the fraction before simplifying, $\frac{\cos^2 x}{\cos^2 x} + \frac{\sin^2 x}{\cos^2 x} = 1 + \tan^2 x$. That form is handy when the answer should be written in terms of $\tan x$ alone.

## The chain rule version: derivative of tan(u)

$$\frac{d}{dx}\,\tan u = \sec^2 u\cdot u'$$

| Function | Inside $u$ | Derivative |
| --- | --- | --- |
| $\tan(4x)$ | $4x$ | $4\sec^2(4x)$ |
| $\tan(x^2)$ | $x^2$ | $2x\sec^2(x^2)$ |
| $\tan\sqrt{x}$ | $\sqrt{x}$ | $\frac{\sec^2\sqrt{x}}{2\sqrt{x}}$ |
| $\tan(e^x)$ | $e^x$ | $e^x\sec^2(e^x)$ |

## Worked examples

**Example 1: a power of tan.** $\frac{d}{dx}\tan^2 x = 2\tan x\cdot\sec^2 x$. Here tan is the inside and the square is the outside.

**Example 2: a product.** $\frac{d}{dx}(x\tan x) = \tan x + x\sec^2 x$, by the [product rule](/rules/product-rule).

**Example 3: a tangent line.** At $x = \frac{\pi}{4}$, $\tan\frac{\pi}{4} = 1$ and the slope is $\sec^2\frac{\pi}{4} = (\sqrt{2})^2 = 2$:

$$y = 1 + 2\left(x - \frac{\pi}{4}\right)$$

**Example 4: second derivative.** $\frac{d}{dx}\sec^2 x = 2\sec^2 x\tan x$, worked out on the [derivative of sec²x](/derivatives/sec-squared-x) page. It is negative for $x < 0$ and positive for $x > 0$, so $\tan x$ has an inflection point at the origin.

## How to remember it

Tangent is the slope of a line from the origin at angle $x$. As the angle approaches a right angle, that slope shoots up, and so does $\sec^2 x$. At $x = 0$ the tangent graph passes through the origin at a 45 degree angle, matching a derivative of $1$.

## Common mistakes

1. **Writing $\sec x$ instead of $\sec^2 x$.** The square matters. $\frac{d}{dx}\sec x = \sec x\tan x$, a different result.
2. **Writing $\sec^2 x\tan x$.** That is the derivative of $\frac{1}{2}\sec^2 x$, not of $\tan x$.
3. **Applying the formula at an asymptote.** $\tan x$ and its derivative do not exist at $x = \frac{\pi}{2} + k\pi$.

Reading the formula backward gives $\int\sec^2 x\,dx = \tan x + C$, see the [integral of sec²x](/integrals/sec-squared-x). For $\int\tan x\,dx$, see the [integral of tan x](/integrals/tan-x).

## Frequently asked questions

### What is the derivative of tan x?

The derivative of $\tan x$ is $\sec^2 x = \frac{1}{\cos^2 x}$.

### Why is the derivative of tan x sec² x?

Write $\tan x = \frac{\sin x}{\cos x}$. The quotient rule gives $\frac{\cos^2 x + \sin^2 x}{\cos^2 x} = \frac{1}{\cos^2 x} = \sec^2 x$.

### What is the derivative of tan(2x)?

By the chain rule, $2\sec^2(2x)$.

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

It is $2\tan x\sec^2 x$. The outer function is the square and the inner is $\tan x$.
