Note: The original poster says, that ties indicate failure (which I read as meaning B succeeds on a tie). This is wrong! In D&D 3.5 the one with the higher bonus wins a tie, and if this bonus is also tied, then the roll is repeated. The following is how it actually works in D&D.
A simple, but slightly tedious (still doable in such simple examples and you do not need a formula), way to find out the probability is to just add up all probabilities for B to beat a particular roll (from 1 to 20 on the d20) from A and then divide the sum by 20 to get the average.
That would be:
20: 0% (result is 30, B can at most achieve a 25)
19: 0%
18: 0%
17: 0%
16: 0%
15: 0% (since A wins ties with the higher bonus)
14: 5% (result is 24, B needs to roll a 20 to beat it)
13: 10% (result is 23, B needs to roll a 19-20 to beat it)
...
2: 65% (result is 12, B needs to roll a 8-20 to beat it)
1: 70% (result is 11, B needs to roll a 7-20 to beat it)
So, we have to add up 14 numbers with a 5% increment.
We can use the n*(n+1)/2 formula (which gets us the sum of all natural numbers from 1 to n) to do so quicker, adding together the numbers 1 through 14 and then multiply by the increment (5%), but simply adding them all together works the same.
14*15/2=105 *5%=525% total.
Now divide by 20 to get the average.
525% / 20 = 26.25% on average.
So there's a 26.25% chance that B beats A, or a 73.75% (=100%-26.25%) chance, that A succeeds.
As for a general formula, we only need to put in variables instead of the constants there.
Since the higher bonus always wins on a tie in D&D (unlike what was written in the original post), we only need to look at Z=X-Y (as in a post above), the difference between the higher bonus (X ~ A's bonus in the example) and the lower bonus (Y ~ B's bonus in the example). This only works for a difference greater than 0, that is, when one bonus is actually higher than the other (the case of a tied bonus is covered later).
n (from the n*(n+1)/2 formula) is 19-Z then, because the one with the lower bonus needs to roll 2 (!) higher to beat the one with the higher bonus at least (with the smallest difference of only 1 between the bonuses), again, because the higher bonus wins ties.
Mixing these into the above and juggling it all together, we come to the following:
100% - [(19-Z)*(19-Z+1)/2 *5% /20] ; Z=X-Y; X>Y.
Or more condensed:
100% - [(19-Z)*(20-Z)/8]% ; Z=X-Y; X>Y.
This is the chance for the one with the higher bonus to succeed (if one bonus is higher, that is).
In the special case, that the bonuses are equal, the above formula doesn't work properly, because you need to figure in the re-roll when the two rolls are tied and the re-re-roll and re-re-re-roll and so on, if you continue to roll a tie).
However, it's simple enough to figure out that probability without any formulas, as it is exactly 50%, obviously.
Bye
Thanee