The 2^n - 1 Prior Work Penalty & Survival 39-Level Cap
Every item or enchanted book modified in an anvil tracks how many generations of anvil operations produced it. In Java Edition 1.20.5 through 1.21.4, this state lives inside the minecraft:repair_cost data component (stored as the RepairCost integer tag prior to 1.20.5). Rather than storing the raw operation counter n (often called anvil uses), Minecraft stores the evaluated penalty 2^n - 1 directly and updates it via AnvilMenu.calculateIncreasedRepairCost(oldCost) = oldCost * 2 + 1.
When you place a Target item in the left anvil slot with u_T prior anvil uses and a Sacrifice item or enchanted book in the right slot with u_S prior anvil uses, the server computes two quantities simultaneously: the immediate level surcharge billed to the current craft, and the inherited u_out counter written onto the resulting output item.
priorWorkCost = (2^u_T - 1) + (2^u_S - 1)
u_out = max(u_T, u_S) + 1 ⇒ nextRepairCost = 2^(u_out) - 1
totalAnvilCost = priorWorkCost + enchantTransferCost + durabilityRepairCost + renameCost
In Survival and Adventure modes (!player.getAbilities().instabuild), if totalAnvilCost ≥ 40 (unless performing a standalone rename), the anvil blocks output extraction and displays "Too Expensive!", enforcing a strict 39-level ceiling per operation.
Because 2^n - 1 doubles and adds 1 on every generation, the sequence of prior work penalties evaluates to 0, 1, 3, 7, 15, 31, 63 for n = 0 through 6. Once any item reaches u = 6 anvil uses, its intrinsic minecraft:repair_cost becomes 63. Even combining that item with a 0-use Mending book (2 levels) yields 63 + 0 + 2 = 65 ≥ 40, permanently bricking the item from accepting further enchantments or unit repairs in Survival mode. Only running the item through a Grindstone resets minecraft:repair_cost back to 0—at the cost of stripping every non-curse enchantment.
Notice the asymmetry inside u_out = max(u_T, u_S) + 1. Combining an item at u_T = 2 with a fresh book at u_S = 0 produces an output at u_out = 3. Combining that same u_T = 2 item with a pre-merged 4-enchantment book that is also at u_S = 2 still produces u_out = max(2, 2) + 1 = 3! Pre-combining books in parallel branches lets you pack exponentially more enchantments (2^k leaves) into the exact same final u = k anvil-use depth.
Enchantment Transfer Multipliers (Book vs. Item)
Aside from prior work penalties, enchantTransferCost depends on whether the right-slot sacrifice is another gear piece or an Enchanted Book. In Java 1.21.4, each enchantment's JSON definition specifies an anvil_cost integer (1, 2, 4, or 8). When sacrificing an item, you pay finalLevel × anvil_cost; when sacrificing an Enchanted Book, the per-level multiplier is halved via integer division clamped to at least 1: bookMultiplier = max(1, floor(anvil_cost / 2)).
| Rarity Tier (Table Weight) | Representative Enchantments | Item Multiplier / Lvl | Book Multiplier / Lvl | Max Tier Book Cost |
|---|---|---|---|---|
| Common (Weight 10) | Protection IV, Sharpness V, Efficiency V, Power V, Loyalty III | 1 |
1 |
Prot IV = 4, Eff V = 5 |
| Uncommon (Weight 5) | Feather Falling IV, Unbreaking III, Smite V, Fire/Proj Prot IV, Quick Charge III | 2 |
1 |
FF IV = 4, Unb III = 3 |
| Rare (Weight 2) | Depth Strider III, Mending I, Fortune III, Looting III, Blast Prot IV, Fire Aspect II, Respiration III, Sweeping Edge III | 4 |
2 |
DS III = 6, Mending = 2, Blast IV = 8 |
| Very Rare (Weight 1) | Soul Speed III, Thorns III, Swift Sneak III, Silk Touch I, Infinity I, Channeling I | 8 |
4 |
Soul Speed III = 12, Thorns III = 12, Silk = 4 |
Crucially, the anvil only sums enchantment multipliers for enchantments on the right-slot sacrifice, never for enchantments already sitting on the left-slot target. Placing a Soul Speed III book (12 levels) in the left slot and a Mending book (2 levels) in the right slot costs 2 levels, whereas reversing the two slots costs 12 levels for the exact same output book! Always keep higher-cost enchantments on the left branch of every pair.
Worked Proof: 7-Enchantment God Boots (Linear vs. Binary Tree)
Boots represent the hardest enchanting puzzle in Vanilla Survival because a maxed pair accepts seven mutually compatible enchantments: Soul Speed III (book cost 12), Thorns III (12), Depth Strider III (6), Protection IV (4), Feather Falling IV (4), Unbreaking III (3), and Mending (2). Let us prove why a naive 1-by-1 linear chain is mathematically impossible from 0-use books, and then construct the globally optimal balanced binary tree.
In any linear chain where clean Netherite Boots (u = 0) absorb seven single-enchantment books one at a time, the boots increment from u = 0 up to u = 6 after the sixth book. Even if you sort the books strictly from highest cost (12) down to lowest cost (2) to minimize late-stage costs, Step 6 (Boots u=5 + Unbreaking III) costs 31 + 3 = 34 levels, pushing the boots to u = 6 (priorWorkPenalty = 63). On Step 7, adding Mending (2) demands 63 + 2 = 65 levels—triggering "Too Expensive!" every time. If applied cheapest-first, the boots brick on Step 6 (31 + 12 = 43 ≥ 40) before the seventh book is even touched.
Now organize all 8 fresh inputs (Boots + 7 books, each at u = 0) into a height-3 balanced binary tree. In a depth-3 tree, the leftmost leaf (the Boots) is paid 0 times as a right-slot sacrifice; three leaves are paid 1×; three leaves are paid 2×; and the rightmost leaf is paid 3× (matching binomial row 1, 3, 3, 1). By the rearrangement inequality, assigning our sorted book costs (12, 12, 6) to the 1× slots, (4, 4, 3) to the 2× slots, and (2) to the 3× slot achieves the strict global minimum level sum:
| Combine Step | Left Slot (Target) | Right Slot (Sacrifice) | Sacrifice Enchants | Prior Work (u_T + u_S) | Step Level Cost | Output Uses |
|---|---|---|---|---|---|---|
| 1 (Tier 1) | Netherite Boots (u=0) |
Soul Speed III Book (u=0) |
12 |
0 + 0 = 0 |
12 levels | u = 1 (pen 1) |
| 2 (Tier 1) | Thorns III Book (u=0) |
Protection IV Book (u=0) |
4 |
0 + 0 = 0 |
4 levels | u = 1 (pen 1) |
| 3 (Tier 1) | Depth Strider III Book (u=0) |
Feather Falling IV Book (u=0) |
4 |
0 + 0 = 0 |
4 levels | u = 1 (pen 1) |
| 4 (Tier 1) | Unbreaking III Book (u=0) |
Mending Book (u=0) |
2 |
0 + 0 = 0 |
2 levels | u = 1 (pen 1) |
| 5 (Tier 2) | Boots [SS3] (u=1) |
Book [Th3 + P4] (u=1) |
12 + 4 = 16 |
1 + 1 = 2 |
18 levels | u = 2 (pen 3) |
| 6 (Tier 2) | Book [DS3 + FF4] (u=1) |
Book [U3 + M1] (u=1) |
3 + 2 = 5 |
1 + 1 = 2 |
7 levels | u = 2 (pen 3) |
| 7 (Tier 3) | Boots [SS3, Th3, P4] (u=2) |
Book [DS3, FF4, U3, M1] (u=2) |
6 + 4 + 3 + 2 = 15 |
3 + 3 = 6 |
21 levels | u = 3 (pen 7) |
Every step clears the 39-level limit with 18 levels of safety margin, summing to 68 total levels (or just 1,456 raw XP points if paid individually from level 0—see our Minecraft XP Level Equations guide). Better yet, the finished God Boots exit at u = 3 (minecraft:repair_cost = 7), leaving two additional anvil generations if needed. Use our Anvil Enchantment Order Optimizer to compute optimal trees when some books already carry pre-existing anvil uses or combined Librarian trades from villager curing.
Renaming Rules, Durability Repair & Edition Parity
Three subtle code paths inside AnvilMenu.createResult frequently surprise experienced players:
- Bundled vs. Standalone Renaming: Typing a custom name always adds
renameCost = 1level. If you rename an item during one of your scheduled enchantment merges (for example, adding a name during Step 7 above for21 + 1 = 22levels),u_outstill only increases by+1—giving you a permanently zero-penalty rename! Conversely, renaming an item by itself incrementsu_outby a full generation. - The 39-Level Pure-Rename Clamp: Decompiled Java code explicitly checks
if (namingCost == addedCost && namingCost > 0 && totalCost >= 40) totalCost = 39;. Consequently, even an over-repaired heirloom weapon withrepair_cost = 63can still be renamed by itself for flat 39 levels! - Unit & Sacrifice Durability Costs: Repairing damaged gear with raw materials (e.g., Diamonds or Netherite Ingots) restores
25%of max durability per unit at+1level per material consumed, plus fullpriorWorkCost. Combining two damaged items adds a flat+2repair levels (plus 12% bonus durability) alongside any enchantment transfers.
Java Edition (1.21.4)
Pays the full resulting tier on upgrades (combining two Protection III books into Protection IV charges 4 × 1 = 4 levels, not 1). Incompatible enchantments on the right-slot sacrifice add a +1 level penalty per conflicting enchantment.
Bedrock Edition (1.21.50)
Pays only the net level increase ((newTier - oldTier) × multiplier), so merging two Protection III books charges just (4 - 3) × 1 = 1 level. Incompatible sacrifice enchantments add 0 penalty levels, making mixed loot books cheaper to apply.
/give @s minecraft:netherite_boots[minecraft:repair_cost=63] in Java 1.21.4 Survival mode (/gamemode survival, /xp set @s 100 levels). Place the boots in an anvil with a Mending book: the UI displays red "Too Expensive!" (65 levels in Creative). Remove the book and alter only the item's text name: the anvil clamps the cost from 64 down to exactly 39 levels and permits output extraction. Inspect output components afterward via /data get entity @s SelectedItem.components."minecraft:repair_cost" to verify it doubled to 127.