For example, for $3$ balls and $3$ bins we have:
1: 1 2 3 (one ball in every bin)
2: 1 2 2
3: 1 3 3
4: 2 1 1
5: 2 3 3
6: 3 1 1
7: 3 2 2
8: 1 1 1
9: 2 2 2
10:3 3 3 (three balls in the third bin)
What is theory for it? I mean, that is the name of the formula, to let me read about it. Thanks.
I suggest you study the Stars and Bars method. In this case, you have three bins (2 bars) and three balls (three stars). This gives 3 + 2 = 5 positions. You can place the 2 bars in any of the 5 positions which gives $\binom{5}{2} = 10$ possibilities or you can place the 3 stars in any of the 5 positions: $\binom{5}{3} = 10$ possibilities:
$$ 1: 0|0|3\rightarrow ||*** \\ 2: 0|1|2\rightarrow |*|**\\ 3: 0|2|1\rightarrow |**|* \\ 4: 0|3|0\rightarrow |***| \\ 5: 1|0|2\rightarrow *||** \\ 6: 1|1|1\rightarrow *|*|* \\ 7: 1|2|0\rightarrow *|**| \\ 8: 2|0|1\rightarrow **||* \\ 9: 2|1|0\rightarrow **|*| \\ 10: 3|0|0\rightarrow ***|| $$