Experience (XP)
Give yourself experience points or XP levels with the /xp or /experience command.
Commands
/xp add @s 30 levels Adds 30 experience levels
/xp add @s 10000 points Adds 10,000 experience points
/xp set @s 100 levels Sets your level to exactly 100
/xp set @s 0 levels Resets your experience level to 0
How it works
In Minecraft, you need experience (XP) to enchant items and to repair them on an anvil. The /xp or /experience command lets you add or set an exact number of experience points or levels. In Java Edition, /xp add @s 1000 points adds 1,000 points and /xp add @s 30 levels adds 30 levels. The difference between points and levels matters: points fill up your experience bar, while levels raise your level number right away. The best enchantments at an enchanting table need level 30, and repairs on an anvil cost from 1 to 39 levels. Leveling up isn't linear: the higher your level, the more points you need for the next one. Reaching level 30 takes 1,395 points, but level 50 takes 5,345. The /xp set @s 0 levels command resets your level to 0. On servers, plugins like Jobs Reborn and mcMMO add their own XP systems that work separately from the vanilla one.
Practical tips
Reaching level 30 takes 1,395 XP, which is enough for the best enchantments.
In Bedrock, the syntax is /xp 30L @s (L = levels) or /xp 1000 @s (points).
The XP system isn't linear: higher levels take more and more points.
You lose your XP when you die, but /gamerule keepInventory true keeps your XP too.