The value of tan B = 2 implies that the sides of the right triangle are in the ratio 2:1.
We can use the Pythagorean theorem to find the hypotenuse. If we let the opposite side be 2 (for tan B = opposite/adjacent), and the adjacent side be 1, then the hypotenuse h is:
h = sqrt(2^2 + 1^2) = sqrt(5)
The cosine of an angle in a right triangle is defined as the ratio of the adjacent side to the hypotenuse. So,
cos B = adjacent/hypotenuse = 1/sqrt(5)
So, cos B = 1/sqrt(5).