Four ways to get enchantments: Enchanting Table (cheapest, random), Fishing (early game), Villager Trading (best for specific books), Loot Chests (free, unreliable).
15 bookshelves in a 5x5 ring with 1-block gap. This unlocks Level 30 the only tier worth using. Build near your bed.
Three random options. Bottom slot at Level 30 gives the best combination. Always use the bottom slot with 30 levels and 3 lapis lazuli.
AFK fish farm with Luck of the Sea III + Lure III. Can yield Mending books. Best early-game source if no villager is available.
Librarians offer random enchanted books. Place lectern, check trade, break/replace to reroll. Lock in Mending immediately.
Cure zombie villagers (weakness potion + golden apple) for permanent 1-emerald trades.
Find a Mending villager first. Break and replace the lectern until Mending appears. A Mending villager is the most valuable asset in any Minecraft world.
The enchanting table uses a complex algorithm involving bookshelf count, enchantment level, and random seed. Each enchantment option shows only the most prominent modifier — several secondary enchantments may also apply. For a deep dive into Minecraft enchanting mechanics and exactly how the algorithm works, check the Minecraft Wikipedia article. The complete enchanting reference with level formulas, conflict tables, and item-specific enchantability values is available on the Minecraft Wiki on Fandom.