Simple example with three balls: red, green and blue.
When we form a collection of two balls, we have
$$
3^2
$$
possibilities.
But some do not contain the same color - and that is given by
$$
3 \times 2
$$
So the number of collection such that two balls have the same color is given by
$$
3^2 - 3 \times 2 = 3
$$
So the change of finding two balls with the same color in a collection of 2 balls is given by
$$
\frac{3^2 - 4 \times 3}{3^2} = \frac{3}{9} = \frac{1}{3}
$$
We can do the same for 4 balls and a collection of 2 balls.
the change of finding two balls with the same color in a collection of 2 balls is given by
$$
\frac{4^2 - 4 \times 3}{4^2}
$$
The basic formula is then given by
$$
\frac{F^n - F \times (F-1) \times (F-2) \times \cdot (F-n)}{F^n}
$$
where
$$
F
$$
is the 'freedom' - the number of different colors for the balls, and
$$
n
$$
is the number of balls in the collection.
Using some math we can write
$$
1 - \frac{F!}{F^n \big(F-n\big)!}
$$
Note that when $n>F$ we have
$$
k!
$$
for a negative number.
But as
$$
\big(n-1\big)! = \frac{n!}{n}
$$
we see that
$$
\big(-1\big)! = \frac{0!}{0} \rightarrow \infty
$$
So in case $n > F$ the change becomes $1$
Instead of color - we can consider birthdays, so $F=365$ and we get
$$
1 - \frac{365!}{365^n \big(365-n\big)!}
$$
The case $n=23$ gives
$$
1 - \frac{365!}{365^23 \big(365-23\big)!} = 50.7\%
$$