What is the max enchantment level using commands?
1.13+ players, please see the other answer.
1.12−
Enchantment levels are saved as a Short, with a minimum of -32,768 and maximum of 32,767.
/give @p minecraft:stone 1 0 {ench:[{id:16s,lvl:32767s}]}
You can find further information on the NBT format here.
1.13+ Update
From the Minecraft Wiki:
lvl: The level of the enchantment, where 1 is level 1. Saved as short when created by enchanting tables or loot tables, but read as an int and supports full int range.
In layman's terms, the Survival means like loot tables, anvils, and enchanting tables save the number as a Short, but when they are actually applied to items, they are read as an Integer.
Therefore, you don't need to stick to the Short data type just because that is what the enchantment tables use. You are allowed to use the Integer data type because that is how the enchantment levels are read.
The maximum integer is 2,147,483,647.
/give @s netherite_sword{Enchantments:[{id:"minecraft:sharpness",lvl:2147483647}]}
Side notes...
- Some users are suggesting that higher enchantment levels are possible, like 2,177,548,418,058. These numbers are from Phoenix SC's video, where the title is "Duplicating OP Enchantments in Minecraft". This shows that the big number was only obtained by stacking enchantments, and is not the maximum level of a single enchantment. You can do what they did and stack your enchantments to obtain higher levels.
- Do note that attempting to exceed the maximum enchantment level using commands will not return an error, but note that the item you receive will have the enchantment level 0. This is because the invalid numbers become strings when inputted incorrectly, and because Minecraft is looking for an integer in the level, it does not register the number because it is a string!