Estimation population size using sampling - real life probability I have come across similar questions like this previously but I just can't get my head around a correct method

Clive catches 50 bees from the beehive and marks each bee with a dye then lets them go.
The next day he catches 40 bees from the hive. 8 of these bees have been marked with dye.
Work out an estimate for the number of bees in the beehive

I has a slight guess that the probability of picking 8 out of the 40 in the second day is the same as the probability of picking 50 out of the total $N$ in the first day so $\frac{8}{40}=\frac{50}{N}$ to give $N=250$ which I think was correct, but I am struggling to convince myself that the logic behind this is true
Also I tried another method using probability but it didn't work and I really don't know why.
I used the fact that $ P(B|A)=\frac{P(A and B)}{P(A)}$ so if $N$ was the total population that we tried to find, then the $P(A and B)$ = $\frac{82}{N}$ ,
$P(A) =\frac{50}{N}$
and the probability of B given A is the 8 out of the total bees so $P(B|A)= \frac{8}{N}$
Hence from this we work out that $N=4.878$ which really cannot be true
Please could someone unpick where I have went wrong and perhaps suggest a better way of tackling these types of animal sampling questions?
 A: According to the Maximum Likelihood estimation your estimation should be $250$ bees.
By seeing that $8$ out of the $40$ bees you caught the second time, are marked, you assume that the $\frac{8}{40}=\frac{1}{5}$ of the total population of the bees are marked, so you say that if the $\frac{1}{5th}$ of the population is 50, then the population must be $5*50=250$.
But why do we assume that $\frac{8}{40}=\frac{1}{5}$ are marked?
This is the Maximum Likelihood estimation.
Let's define $\theta$ as the percentage of marked bees after your first visit in the hive.
Let's also define $X$ as the number of marked bees you found on your second visit in the hive and $n$ the total number of bees you found on your second visit in the hive.
Then the function:
$L(\theta)=\binom{n}{X}\theta^X(1-\theta)^{n-X}$ 
gives you the probability of getting $X$ marked bees out of $n$ total bees for a percentage $\theta$ of marked bees in the population. If you maximize this function you will find out that it has a maximum for $\theta = \frac{X}{n}$. 
Here the function is:
$L(\theta)=\binom{40}{8}\theta^8(1-\theta)^{40-8}$
and it is maximized for $\theta=\frac{1}{5}$.
Generally speaking the method of Maximum Likelihood estimate is like asking yourself: 
"From which population did this data came?"
And answering:
"From the population where this data would be most likely to appear"
Here the "population" of the answer would be a population with $\frac{1}{5}$ marked bees. So the 50 (marked) bees must be the $0.2$ of the total number of bees, thus making the the total number of bees 250 bees.
