The gain uses the room left in each preferential band
Other taxable income fills the 0% and 15% ceilings first. Only the leftover room is available to the gain. That is why two people with the same $20,000 gain can owe different tax on it: one still had 0% room, the other did not.
The 2026 ceilings come from Revenue Procedure 2025-32. Amounts above the 15% ceiling are taxed at 20%.