The D&D 5th edition Player's Handbook, page 201 (under "What Is a Spell"), describes it thusly:
A spell is a discrete magical effect, a single shaping of magical energies that suffuse the multiverse into specific, limited expression. In casting a spell, a character carefully plucks at the invisible strands of raw magic suffusing the world, pins them in place in a particular pattern, sets them vibrating in a specific way, and then releases them to unleash the desired effect—in most cases, all in the span of seconds.
Words and actions
A spell, such as fireball, can have verbal components (words which must be spoken to invoke the magic), somatic components (physical movements which must be made), and material components (objects or substances used to focus the magic).
While material components are frequently detailed, the exact words and movements are not described in the game's rules, and are left to the players' imagination. Forgotten Realms author Ed Greenwood once described how he was asked to include the actual verbal components of spells in a novel, but that the editor ended up deleting them anyway.
In D&D 5th edition, the wizard who wishes to cast fireball must first "prepare" that spell, usually at the start of the adventuring day while well-rested, which fixes the spell in their mind. The Vancian term "memorize" has actually not been used since AD&D 2nd edition. In 5th edition, the wizard casts the prepared spell by performing specific verbal and somatic components.
Those components are never detailed in the rules, but we do know the following about them:
- They take less than a second.
- According to Xanathar's Guide to Everything, p. 85, "Identifying a Spell", someone familiar with magic may identify the spell being cast by watching the verbal and somatic components. Someone of that class has advantage on the check. However, success is not automatic even if you know the spell yourself, from which we may deduce that not every spellcaster uses exactly the same verbal and somatic components, and different classes have their own unique verbal and somatic components.
- Most wizards never invent their own spells. We might conclude that working the strings of magic is a highly complex thing, where learning what earlier wizards have done is still easier than inventing it yourself. We can surmise that it would not be trivial, for example, to make a square or oval fireball, or a lightning-fireball, just by changing one word or gesture. Sorcerers, with a more innate and intuitive knowledge of magic, are more capable of such metamagic.
Source of power
In the Forgotten Realms setting, the source of magic tapped by wizards is termed The Weave, a unique feature of that setting. In other worlds (those of Eberron, Greyhawk, etc), there is no such named source of magic, but spells nonetheless work much as they do in the Realms. Any given DM's setting may have its own unique rules for where magic comes from.
D&D 5th edition describes it simply as shaping magical energies which suffuse the multiverse and drawing energy from them. There's no more specific description given. One might easily conjecture, for example, that fireball comes from the Plane of Fire, but there's no actual source to back that up in the rules, and any number of possible explanations are valid.
In the original D&D, Gygax appears to have based some of his spells on real-world historical practices of folk magic or witchcraft, in which magic often simply works based on specific ritual without necessarily understanding the source of that effect in any modern scientific way. For example, Deuteronomy 18:10, written c. 600 BC, forbids various forms of witchcraft (suggesting that those practices existed at that time), while the concept of a magic circle comes from more recent occult magic (16th century onward).
Ultimately, the way magic "works" in D&D (beyond what is described in the rulebooks) is really up to the player's imagination, and is not described in particular detail.