Normal Chance to Hit
Your chance to hit can be calculated by:
$$\frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }$$
Note that attack bonus is your total attack bonus with all modifiers. We can test this out pretty easily. If you have a +7 to hit and are attacking a target with AC of 18, you need an 11 to hit. 11 through 20 is 10 faces on the d20, so it's half the die. A 50% chance to hit.
$$\frac{ 21 + 7 - 18 }{ 20 } = 0.50$$
And so it is.
If you are attacking the same AC 18 target and have a +2 attack bonus, you need a 16 or better to hit. You hit on 16, 17, 18, 19, or 20. That's five of the twenty sides of a d20, which is a quarter or 25% of the die.
$$\frac{ 21 + 2 - 18 }{ 20 } = 0.25$$
And so it is.
It's also worth remembering that a natural 1 always misses and a natural 20 always hits regardless of the attack bonus or AC involved. If you need a natural 20 to hit, your chance to hit is \$\frac{1}{20} = 0.05\$ (5%). This is the minimum chance to hit. If you need a natural 2 or better to hit, your chance to hit is \$\frac{19}{20} = 0.95\$ (95%). This is the maximum chance to hit.
Chance to Hit with Disadvantage
If you have disadvantage, you effectively have to hit with both die rolls. To calculate that, simply multiply the chance to hit by itself.
$$\left(\frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }\right) \times \left(\frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }\right)$$
Which can be simplified to:
$$\frac{ (21 + Attack\,Bonus - Target\,AC)^2 }{ 400 }$$
So, with an an attack bonus of +7 and AC 18, the chance to hit with disadvantage is:
$$\frac{ (21 + 7 - 18)^2 }{ 400 } = \frac{ 10^2 }{ 400 } = \frac{ 100 }{ 400 } = 0.25$$
Again, a natural 1 always hits and a natural 20 always misses. If you need a natural 20 to hit, your chance to hit is \$\frac{1}{400} = 0.0025\$ (0.25%). This is the minimum chance to hit with disadvantage. If you need a natural 2 or better to hit, however, your chance to hit is \$\frac{19^{2}}{400} = \frac{361}{400} = 0.9025\$ (90.25%). This is the maximum chance to hit with disadvantage.
Chance to Hit with Advantage
If you have advantage, it's a little bit more complex. Here, we have to calculate if either die hits or both dice hit. It turns out to be easier to calculate the chance to miss. That is, the chance to hit with advantage is equal to the chance to not miss with both dice. If the chance to hit is this:
$$\frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }$$
Then the chance to miss with one die is:
$$1 - \frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }$$
This is true because you either hit or miss, so the chances of hitting or missing always total to 1 (or 100%).
And the chance to miss with both dice is just the product of missing with each die. We used that above when calculating to hit with disadvantage:
$$\left(1 - \frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }\right) \times \left( 1 - \frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 } \right)$$
So, the chance to hit with advantage is the above subtracted from 1:
$$1 - \left[ \left(1 - \frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 }\right) \times \left( 1 - \frac{ 21 + Attack\,Bonus - Target\,AC }{ 20 } \right) \right]$$
Which simplifies to:
$$1 - \frac{(Target\,AC - Attack\,Bonus - 1)^2 }{ 400 }$$
(Note the AC and attack bonus swapped places in the simplified formula. You could also write it as \$1 - \frac{(1 + Attack\,Bonus - Target\,AC)^2 }{ 400 }\$, but this is how Wolfram Alpha simplified my algebra.)
So, with an an attack bonus of +7 and AC 18, the chance to hit with advantage is:
$$1 - \frac{(18 - 7 - 1)^2 }{ 400 } = 1 - \frac{{10}^2 }{ 400 } = 1 - \frac{100}{400} = 1 - 0.25 = 0.75$$
And, of course, a natural 1 always misses and a natural 20 always hits. If you need a natural 20 to hit, your chance to hit is \$1 - \frac{(19)^{2}}{400} = 1 - \frac{361}{400} = 0.0975\$ (9.75%). That is the minimum chance to hit with advantage. If you need a natural 2 or better to hit, your chance to hit is \$1 - \frac{(1)^{2}}{400} = 0.9975\$ (99.75%). That is the maximum chance to hit with advantage.