How is tax on social security benefits calculated?

My wife earned about $36,000 in 2017, and my Social security benefits were roughly $24,000, for a gross income of $60,000 (married filing jointly). It is perplexing to see how much tax I still have to pay, especially on my social security benefits.  How do they calculate this figure?