There are formulas out there, but they're far from elegant and much easier to implement in a software program than do them manually.
To calculate the probability of getting a certain result S on a roll of N M-sided dice, use the following:
P(S) = (M^(-N))*SUM(from k=0 to Floor((S-N)/M))[(-1)^k * C(N,k)*C((S-1-M*k),N-1) where C(x,y) implies x!/(y!*(x-y)!)
Complicated but simple in a PC.

Hope I got that down correctly.
Let's see. For rolling 5 on a 1d6:
M=6,N=1,S=5: The floor function is 0 (rounding down 5/6), with k hence only being 0 to 0. C(N,k) is C(1,0) which is 1, while the other C function is C(4,0) which is 1 as well.
So the probability boils down to 1/6*1*1*1=1/6 which it should be.
Edit: You can check out the following online calculator for this formula:
http://www.vrtisworks.com/kiki/fun/cdice.htm
Pinotage