Rebalancing is a risk-control mechanism first. Left alone, a portfolio drifts toward whatever asset has performed best, so its risk quietly rises at exactly the point when that asset is most expensive. Rebalancing forces the opposite behaviour.
Example: a 60/40 portfolio of $200,000 starts with $120,000 equities and $80,000 bonds. Equities gain 25% to $150,000 while bonds are flat, so the total is $230,000 and equities are 65.2%. Returning to 60% means selling $12,000 of equities and buying bonds with the proceeds.
The costs are real: commissions, spreads, and in a taxable account a capital gains bill. This is why most investors use bands rather than continuous adjustment, and why new contributions are directed to the underweight asset first. See rebalancing-bands and tax-aware-rebalancing.
Related: asset-allocation, rebalancing-bands, portfolio-drift, calendar-rebalancing, tax-aware-rebalancing