Let f (x) = x T Ax + 2a T x + c and h(x) = x T Bx + 2b T x + d be two quadratic functions having symmetric matrices A and B. The S-lemma with equality asks when the unsolvability of the system f (x) < 0, h(x) = 0 implies the existence of a real number µ such that f (x) + µh(x) ≥ 0, ∀x ∈ R n . The problem is much harder than the inequality version which asserts that, under Slater condition, f (x) < 0, h(x) ≤ 0 is unsolvable if and only if f (x) + µh(x) ≥ 0, ∀x ∈ R n for some µ ≥ 0. In this paper, we show that the S-lemma with equality does not hold only when the matrix A has exactly one negative eigenvalue and h(x) is a non-constant linear function (B = 0, b = 0). As an application, we can globally solve inf{f (x) : h(x) = 0} as well as the two-sided generalized trust region subproblem inf{f (x) : l ≤ h(x) ≤ u} without any condition. Moreover, the convexity of the joint numerical range {(f (x), h 1 (x), . . . , h p (x)) : x ∈ R n } where f is a (possibly nonconvex) quadratic function and h 1 (x), . . . , h p (x) are affine functions can be characterized using the newly developed S-lemma with equality.