DnD 5e - Spellcasting Class Features
Of the 12 classes in the Player's Handbook, 7 can cast spells by default, and 2 more can gain the ability to cast spells from a subclass (3 if you count monks). Each of these classes has its own entry for the Spellcasting class feature except the Warlock, which gets Pact Magic instead.
When considering a class for your character, the distinctions between the different versions of Spellcasting can be easy to miss. But don't worry: the distinctions are fairly minor, and I've provided a convenient reference table later in this article.
Unlike other spells, cantrips work the same way for everyone. You learn cantrips primarily from your class, though you can also get them from your race and from feats. Once you know a cantrip, you know that cantrip forever. If improves as your characters gains levels (total character levels, not just levels in the class which gave you the cantrip). Classes which grant cantrips will give you a fixed number of cantrips known that will increase very slowly as you gain levels.
Unlike other parts of the Spellcasting class feature, this works the same way for all classes that gain Cantrips, including Warlocks.
Each class has a "spellcasting ability". This is the ability score used to determine how effective you spells are, and affects a number of things, including your number of spells prepared (if applicable), the saving throw DC of your spells, and your spell attack modifier. Some spells add numerical effects based on your spellcasting ability, like the spell healing word which heals additional hit points equal to your spellcasting modifier.
Many spellcasting classes can use an object called a "spellcasting focus". These items allow the spellcaster to use the focus in place of inexpensive material components when casting spells, and waving a wand or a staff about has a certain magical flavor that many players (myself included) really enjoy. Which foci are available vary by class, as described in each class's Spellcasting or Pact Magic entry. For classes that don't allow spellcasting foci, you can always use a Spellcasting Pouch, which fills the same function but isn't nearly as cool
For more on spellcasting foci, see Casting a Spell, later in this guide. For the list of available spellcasting foci, see page 150 of the Player's Handbook.
Spellcasting can be grouped into two major "methods" of spellcasting, which we'll call "Knowledge" and "Preparation". Wizards have a variation on the Preparation Method, and Pact Magic (the thing Warlocks use) is mostly a variation of the Knowledge method with some unique mechanics.
The Knowledge Method
Under this method, the spellcaster learns a certain number of spells as they gain levels. These spells are near-permanently fixed in your mind, and you're always able to cast them so long as you have appropriate spell slots with which to do so. Keep in mind that the number of spells known varies wildly between classes, so be sure to check your class's class table to see how many spells you learn.
Whenever you gain a level in the class that grants you Spellcasting, you can replace one of your spells known with another spell of any spell level that you can now cast at your increased level.
For example: A 1st-level bard knows 4 spells, while a 3rd-level bard knows 6.
Pact Magic is a variation on the Knowledge Method. Warlocks learn spells the same way that bards and sorcerers do, but warlocks spells slots work differently from classes with the Spellcasting class feature: instead of recharging a pool of spell slots of various spell levels after a long rest, Pact Magic grants the spellcaster a small pool of spell slots which are all the same level and all recharge after a short rest.
For more, see the Pact Magic text in the Warlock's class description on page 107 of the Player's Handbook.
The Preparation Method
Under this method, the spellcaster's entire spell list is available to them. After a long rest, the spellcaster can choose to reset their prepared spells, selecting a number of spells from their spell list which they are high enough level to cast.
For example: A 3rd level druid with 16 Wisdom can prepare 6 spells (their druid level plus their Wisdom modifier, as described in the Druid's Spellcasting entry) every day. Since they are 3rd level, they can cast 2nd-level spells, so they can prepare any leveled spell on the Druid spell list up to 2nd level.
Wizards use a slight variation on the Preparation Method. While they prepare spells like clerics and druids, wizards don't have their entire spell list available. Instead, wizards "learn" spells by writing them into a spellbook. Wizards learn more spells over time by adding them to their spellbook, expanding the options for which spells they can prepare every day. A wizard could, in theory, collect every published spell on the wizard spell list and put them into spellbooks, but doing so is expensive, time-consuming, and typically not worth the effort.
Wizards also get to cast ritual spells differently than other spellcasters: while other spellcasters must know the spell or have it prepared, wizards can cast a spell as a ritual so long as the spell is in the wizard's spellbook.
Spellcasting Variations by Class
|Cleric||Preparation||Wis||Level + Wis||Holy symbol||Yes|
|Druid||Preparation||Wis||Level + Wis||Druidic focus||Yes|
|Fighter (Eldritch Knight)||Knowledge||Int||-||-||No|
|Paladin||Preparation||Cha||Half Level + Cha||Holy symbol||No|
|Rogue (Arcane Trickster)||Knowledge||Int||-||-||No|
|Warlock||Pact Magic||Knowledge||-||Arcane focus||No|
|Wizard||Wizard||Intelligence||Level + Int||Arcane focus||Yes*|
|* - See the class's description|
Some creatures, including Tieflings and many monsters, have the ability to cast spells innately without levels in a spellcasting class. This "innate spellcasting" works mostly the same way that spellcasting does. However, the creature can only cast specific spells at specific spell levels, and they don't have spell slots or the ability to cast those spells at higher spell levels.
If a creature knows cantrips innately, their cantrips still improve based on their total levels (or their CR for monsters). For example: High Elves and Tieflings both know a cantrip as part of their racial traits, and these cantrips improve based on the character's total levels.
If a creature has both innate spellcasting and levels in a spellcasting class, the two abilities function separately. The creature can't use their spell slots to cast their innate spells without also having access to that spell via their spellcasting, and they can't use their innate spells to cast spells granted by their spellcasting feature.
Some creatures use Psionics instead of traditional magic. Psionics are nearly identical to spellcasting, at least in mechanical terms, but some other game rule smay refer to psionics. For more, see page 10 of the Monster Manual under "Psionics".