Derivation

For events

P(A|B)=\frac{P(A \cap B)}{P(B)}, \text{ if } P(B) \neq 0, \!

P(B|A) = \frac{P(A \cap B)}{P(A)}, \text{ if } P(A) \neq 0, \!

\implies P(A \cap B) = P(A|B)\, P(B) = P(B|A)\, P(A), \!

\implies P(A|B) = \frac{P(B|A)\,P(A)}{P(B)}, \text{ if } P(B) \neq 0.

For random variables

f_X(x|Y=y) = \frac{f_{X,Y}(x,y)}{f_Y(y)}

f_Y(y|X=x) = \frac{f_{X,Y}(x,y)}{f_X(x)}

\implies f_X(x|Y=y) = \frac{f_Y(y|X=x)\,f_X(x)}{f_Y(y)}.