Hypergeometric Distribution Formula So I just learned the Hypergeometric Distribution Formula but we were not taught how it was derived, I can't find a solution online on why this formula works or any logical reasoning using counting techniques, attached is the formula

 A: Let $(N, n, R)$ be a triple such that $N$ is the total number objects, i.e., population. $n$ is your sample size, and $R$ is the number of "special" objects. As such, if your sample size is $n$ and you draw it without replacement from total number of $N$ objects, you have a total of 
$$
\binom{N}{n}
$$
possible choices. Now, you are interested in getting exactly $x$ special objects, i.e., you have $\binom{R}{x}$ options, and as your sample size is $n$, the other $n-x$ objects have to be "non-special", i.e.,  $\binom{N-R}{n-x}$. Namely, the total number of elementary outcomes that defines your event of interest ("getting exactly $x$ special objects) is
$$
\binom{R}{x}\binom{N-R}{n-x},
$$ 
out of total of 
$$
\binom{N}{n}
$$
outcomes. Hence, 
$$
P_X(x) = \frac{\binom{R}{x}\binom{N-R}{n-x}}{\binom{N}{n}}, \quad x = 0,1,...,\min\{n, R\}\, .
$$
A: The answer by @VVancak is excellent (+1); I hope you will Accept it. Because your question was open-ended, here are further comments that may be of interest.
Suppose an organization has $N = 50$ members, of whom $w = 20$ are women and
$m = 30$ are men. Suppose $n = 7$ of them are selected to serve on an important
committee. If only 2 women are chosen, is that an indication 
committee members were not chosen at random (without regard to gender)?
If selection were make at random, then the distribution of the number $X$ of
women chosen is hypergeometric. The expected number of women chosen would
be $E(X) = n(w/N)$ $= 7(20/50) = 2.8.$ The probability 
$$P(X \le 2) = \sum_{k=0}^2 P(X = k) = 0.4103$$
is found by adding three terms of the hypergeometric distribution of $X,$
so it is not unlikely to get so few women by random
selection
In R, where a hypergeometric CDF is denoted phyper, the computation can be
done as shown below:
phyper(2, 20, 30, 7)
## 0.4103488

A chart of the PDF of this distribution is as follows:

Notes: (1) Impossible values: In some hypergeometric distributions, some of the values from $0$ through $n$ can have $0$ probability. This happens if there are not enough
of favorable or unfavorable population elements to achieve the value $x.$ A common convention
is to define ${a \choose b} = 0$ if $b > a.$ That makes it possible to
write (in the notation of @VVancak) the general PDF formula
$$P_X(x) = \frac{\binom{R}{x}\binom{N-R}{n-x}}{\binom{N}{n}}, \quad x = 0,1,...,n.$$
(2) Comparison with binomial: In my notation for the number of women chosen for the committee, the variance of this hypergeometric distribution is:
$$V(X) = n\left(\frac wN\right)\left(1 - \frac wN\right)\frac{N-n}{N-1}.$$
This looks similar to the binomial variance $np(1-p),$ except for the final
factor, which is sometimes called the 'finite population correction'. Because
the hypergeometric distribution applies to sampling without replacement, its variance is somewhat smaller than the "corresponding" binomial distribution for sampling with replacement. The plot below shows the same hypergeometric
distribution as in the plot above (blue bars) along with the distribution (thin red bars)
of $\mathsf{Binom}(n=7, p=0.4).$

