I want to know do i need to make the sample same like finding the probability of both sample on 500 messages and than do the calculation or i can just calculate it without thinking about the total sample .
The word “password” occurs in 50 of 1000 messages known to be spam and in 5 of 500 messages known not to be spam. Find the probability that an incoming message containing the word “password” is spam, assuming that it is equally likely that an incoming message is spam or not spam.
Let $S$ be the event that a message is spam and $A$ the event that a message contains "password". From the given data we get estimates of conditional probabilities, which we assume to be accurate: $P(A|S) = 50/1000 = 1/20$ and $P(A|S^c) = 5/500 = 1/100$. You are given that $P(S) = P(S^c) = 1/2$. Then Bayes' Theorem says $$ P(S|A) = \dfrac{P(S) P(A|S)}{P(S) P(A|S) + P(S^c) P(A|S^c)}$$
The sizes of the samples influence the accuracy of those conditional probabilities, and thus the accuracy of the result, but they are not used beyond the computation of the conditional probabilities $P(A|S)$ and $P(A^c|S^c)$.