TITLE: Pdf of the difference of two exponentially distributed random variables
QUESTION [42 upvotes]: Suppose we have $v$ and $u$, both are independent and exponentially distributed random variables with parameters $\mu$ and $\lambda$, respectively. 
How can we calculate the pdf of $v-u$?

REPLY [5 votes]: There is an alternative way to get the result by applying the the Law of Total Probability:
$$
P[W] = \int_Z P[W \mid Z = z]f_Z(z)dz
$$
As others have done, let $X \sim \exp(\lambda)$ and $Y \sim \exp(\mu)$. What follows is the only slightly unintuitive step: instead of directly calculating the PDF of $Y-X$, first calculate the CDF: $ P[X-Y \leq t]$ (we can then differentiate at the end).
$$
P[Y - X \leq t] = P[Y \leq t+X]
$$
This is where we'll apply total probability to get
$$
= \int_0^\infty P[Y \leq t+X \mid X=x]f_X(x) dx 
$$
$$
= \int_0^\infty P[Y \leq t+x]f_X(x) dx 
= \int_0^\infty F_Y(t+x) f_X(x) dx 
$$
Note substituting the CDF here is only valid if $t \geq 0$,
$$
= \int_0^\infty (1- e^{-\mu(t+x)}) \lambda e^{-\lambda x} dx 
= \lambda \int_0^\infty e^{-\lambda x} dx - \lambda e^{-\mu t} \int_0^\infty e^{-(\lambda+\mu)x} dx 
$$
$$
=  \lambda \left[ \frac{e^{-\lambda x}}{-\lambda} \right]^\infty_0  - \lambda e^{-\mu t} \left[ \frac{e^{-(\lambda+\mu)x}}{-(\lambda+\mu)} \right]^\infty_0 
=1 - \frac{\lambda e^{-\mu t}}{\lambda+\mu} 
$$ 
Differentiating this last expression gives us the PDF:
$$
f_{Y-X}(t) = \frac{\lambda \mu e^{-\mu t}}{\lambda+\mu} \quad \text{for $t \geq 0$}
$$