Derivatives of Tangent: The Formula You Need and What Goes Wrong When You Use It
The derivative of tan(x) is sec²(x). That is the core formula, and it comes directly from applying the quotient rule to sin(x)/cos(x), or from rewriting tan as (1 - cos(2x))¹ · sin(2x) and simplifying. Both routes land on the same result. Most people memorize the end point without understanding why the identity d/dx[tan(x)] = sec²(x) is true, which is fine until they encounter a problem that does not fit the standard template. Here is the practical version. If you are working with tan(x) and need its derivative, sec²(x) is the answer. If the argument is something more complicated, like tan(f(x)), you multiply by f'(x). The chain rule still applies. People skip that part constantly because sec²(x) looks clean enough to be the whole story. I ran into this recently while building a symbolic computation pipeline. The input involved tan²(3x + 1) in a numerator expansion, and my initial parser returned the derivative as 2sec²(3x + 1) without accounting for the inner function's derivative. The correct result is 6sec²(3x + 1)tan(3x + 1). I had to add a rule that whenever the outer function is tan, the inner derivative gets applied. That one fix removed about half of the misclassified expressions in a batch of roughly 400 test cases.
The quotient-rule derivation itself is worth knowing because it reveals an alternative form that occasionally matters. Since tan(x) = sin(x)/cos(x), differentiating gives: (cos(x) · cos(x) - sin(x) · (-sin(x))) / cos²(x) = (cos²(x) + sin²(x)) / cos²(x)
= 1 / cos²(x) = sec²(x) This form makes it clear why the derivative is always non-negative wherever tan is defined. The numerator collapses to 1 via the Pythagorean identity, leaving 1/cos²(x). That observation helps when checking answers quickly or spotting errors in long symbolic manipulations.
Get the Full Details

There are cases where treating the derivative as simply sec²(x) will mislead you. The function tan(x) has vertical asymptotes at x = /2 + n for every integer n. At those points, the derivative does not exist, and sec²(x) blows up to infinity. Integration across an interval containing an asymptote requires splitting the interval and taking limits. Failing to do that produces incorrect definite integral results, and it is easy to miss because the algebra looks fine until you evaluate numerically. Another subtle point: the second derivative of tan(x) is 2sec²(x)tan(x). If you are doing Taylor expansions around x = 0, the coefficients involve tangent numbers, which grow fast. Using only the first derivative in a low-order approximation introduces noticeable error beyond the linear term. The error accumulates because tan is not a linear function, and sec²(x) itself varies with x. When you are working numerically near the asymptotes, floating-point overflow is a real concern. I encountered a boundary-condition problem where values of x were within 10 of /2. Directly evaluating sec²(x) produced infinities in double precision. The workaround was to rewrite sec²(x) as 1 + tan²(x) and use the stored value of tan(x) rather than recomputing cosine from scratch. This reduced the condition number of the calculation and kept the results in a usable range.
A few additional details that matter when you are implementing this:
- The identity sec²(x) = 1 + tan²(x) is useful when you already have tan(x) available, since it avoids an extra trigonometric call and reduces numerical error.
- For composite arguments, always check whether the inner function is constant or variable. If it is constant, the chain rule factor drops out. If it is variable, it must be included.
- Higher-order derivatives follow a recurrence based on repeated differentiation of sec²(x)tan(x), but closed-form expressions exist only for specific orders and are not generally simpler than computing the derivative step by step.
The tan derivative identity is reliable within its domain, but the domain restrictions are strict. It fails at odd multiples of /2, and it does not handle composite arguments unless the chain rule is applied. When numerical stability is important, prefer the 1 + tan²(x) form over direct sec²(x) evaluation near asymptotic regions.
