Depending on your gross pay, a $20 difference may be "close enough".
Your deductions are only estimates and do not account for prior pay or deductions, future raises, etc. They just take your taxable pay for that period (gross pay less any tax-exempt deductions like 401(k)), extrapolate to determine how much tax you'd owe for the entire year (given your taxable pay and the number of allowances you claim), and determine the portion of tax for that period that should be deducted.
Those variables (taxable pay, period and allowances) are used to look up the amount to deduct in the IRS tax wihholding tables, or calculated using the Percentage Method in the same publication.
When you file at the end of the year, your actual tax will be calculated, and your total deductions will be subtracted from that amount to determine how much left you owe (or how much will be refunded to you).
Medicare and Social Security are different because it is a set percentage of your pay, not bracketed. When you reach the limit for Social Security tax, your employer should just stop deducting it - there is no extrapolation to an annual amount like income tax.
The best way to estimate tax is to estimate how much total taxable income you will have for the year and use the tax brackets to estimate total tax. Mane of the free calculators out there will do that for you, but don't expect the amount deducted from your paycheck to be exact.
If that sounds complex, it is, especially if you itemize deductions and/or have irregular pay. The goal is not to be exact; it's to be close enough so you don't underpay too much and risk penalties or to withhold too much and have a huge refund (which messes up your cash flow).
Another approach to estimate the impact of changes is to look at your marginal tax rate (or tax bracket). If your total taxable income is within a certain bracket, say 25%, then every extra dollar you earn (or pre-tax deduction you add) will increase (reduce) your tax by 25%. That can be more helpful to determine the impact of a raise or increasing retirement than trying to estimate the amount that will be withheld (and is more important).