The three rules of anvil cost
- Every enchantment has a rarity weight (common = 1, rare = 4). Applying it costs levels based on its level and weight.
- Every time an item or book is used on an anvil, its prior work penalty (PWP) increases - and the next anvil use adds 2^PWP - 1 levels from that item's side.
- If a single merge would cost more than 39 levels, the anvil refuses: 'Too Expensive!'. This cap counts everything: enchantment costs plus both prior work penalties.
Why combining order matters
The prior work penalty grows exponentially. A freshly enchanted book has zero prior work, so merging two books costs almost nothing extra. But if you apply books to your sword one by one, the sword's penalty doubles with every step - by the sixth book you are paying dozens of extra levels, or hitting the cap. The fix: merge books with each other first (cheap merges build a single super-book), then apply once to the gear.
Combining books first is almost always cheaper
Two Sharpness I books merge into Sharpness II for a tiny cost. Stack that logic: build up your biggest enchantments into one combined book, merge in the cheap enchantments along the way, and apply the final book to the item in a single anvil use. The calculator automates exactly this: it tries every merge tree and returns the cheapest one.
Naming and other costs
Renaming an item on the anvil adds a small extra cost. Repairing by consuming materials (e.g. iron ingots) also counts as anvil work and increases the penalty. For god gear, do all enchanting first and never use the anvil for repairs - that is what Mending is for.