While both are indeed taxed, dividends are taxed as ordinary income, whereas gains from sale of stock are considered and taxed as capital gains. In the US at least, the capital gains rate is somewhere around 1/4 to 1/2 of the ordinary income rate, so it's much more "tax efficient" to do a buyback than to pay dividends.
In the popular media the impression is that dividends are not taxed as ordinary income. The reason those evil rich trust fund guys pay lower taxes than the secretary etc.