When a company buys its own shares and retires them, each remaining share is a claim on a larger fraction of the same business. The purchase is a good use of cash only if the shares are bought below a careful estimate of intrinsic value, and only if the cash was not needed for a better use. Buying dear, or buying with money the business cannot spare, transfers value the wrong way.
Buybacks and dividends are both ways to return cash. A buyback changes the share count. New shares issued to employees or to sellers of another company can offset it. The figure that matters is the net change.
See dilution and capital allocation.