There have been numbers of times when I tried my best to figure out how magic might possibly work. The simple explanations we keep hearing never cut it to a sufficiently critical analysis.
Let's imagine for a second that magic exists, and there are people who can, by their very nature, somehow use magic (the ritual, not the energy, which is another story completely) to not just change something but to change anything. How does it work?
"Well, I say the words, and the fireball just appears". Ah, but where does the fireball come from? "It just... poofs into existence, I guess". ...right. So, how do your words push the reality into submission? "...it goes into the wall".
Even if we suppose that reality casually transfers energy onto a certain point in physical space which is somehow related to the caster (and is not random, for some reason, despite lack of spacial declaration within the spell) - how does one make reality do that kind of thing? How does a wish transfer into an action with no actor?
Dozens of questions that have no answer most of the time. It doesn't often bother people who read the sort of stories where magic is featured - it is, after all, a fantasy; fiction - but it had been bothering me. Until, that is, I'd found a way to justify magic's existence within a given fictional world. Don't get me wrong: there's nothing wrong with either magic or the unexplained relationship between the caster/the spell and reality. Both are fine, and there's nothing wrong with using those ideas. If we had to, however, justify magic's existence, there's the way:
Programming.
The whole world is a simulation, a program of some sort, and everyone inside of this world can access the console and write some stuff down to make the world around change. Like real programming, this kind of programming requires skill, knowledge and experience to produce great effects, and even then one can't become good with everything. What's to stop one from programming oneself to know everything, then? Because you'd have to know what to affect and how. You can't just assign a number to a function that requires a string (that is, text) - it will throw an error at best - the fact which serves both as a nod to reality and as a balancing issue.
Granted, there are an astonishing number of things to consider as you magic-program, just as there are an astonishing number of variables in reality (given that, as far as we know, every single quantum is a variable affecting millions of others). Which is why, to the people inside the simulation, large amounts of data-crunching come naturally, like movement (a hugely complex sequence of considerations) comes naturally to our world's breathing creatures. It doesn't impose upon them greater intelligence per se - merely allowes them to dig through much more data; whether you become knowledgeable through that feat is still a choice.
I base this on an idea of mine, something that I had for some time now and am still working on. Basically, there's the simulation, and within it live synthetical organisms who (from our perspective) resemble human beings to a degree (being otherwise more durable and physically capable as well as possessing the cognis module - the part of their synthetic brain which does the conscious part of calculations; yet, still capable of emotions and art to not a lesser degree). Synths know perfectly well that their world is a simualtion (which, to them, is utterly natural) and wonder: who might have built it? So far, they've theorized that it might have been a biological person or a group of such persons - humans, dubbed also the Developers or Admins - and if that's true, why did they do that? is there a way to contact them? And so on.
I feel like this works because it doesn't diminish the great magical effects - one can bend most of the things provided they know how to - but it also provides an incentive to work for it, which, if applied to a plot or a character, produces dramatic scenes with no less an effect than in works without magic. You can still be a great sportsman - or you can be a great programmer. There are, of course, balancing issues (like synths' RAM being used in calculations of the written program - if the RAM is overflown, the program doesn't fire at all and might even damage the synth's systems due to a surge of electricity), but it's still magic. The kind of magic that I'd like to see: critically sound given a few axioms I don't have trouble accepting.