Writing speculative fiction — fantasy and science fiction — may feel like freedom to the new author, since the world of the story is up to its creator, but if the reader is going to be able to live in that world for the duration, it must be one that is believable, a world that works at least as much as the plot and the characters use it. Fantasy specifically is often, but not necessarily identified with magic, and if you are going to write stories that include this, you need to have the rules figured out in advance.
The first thing to consider is what, exactly, is magic in the world of your story. The ability to communicate around the globe at a speed that feels instantaneous would sound like magic to someone from the days of the Roman Empire, for example, and the transporters of the Star Trek universe would look the same to us. These are illustrations of Arthur C. Clarke’s Third Law — any sufficiently advanced technology is indistinguishable from magic — and how magic systems differ from science fiction can end up being more quibble than actual distinctions if the world is fully realized. The Potterverse presents magic as something that can be studied, and while J.K. Rowling does not go into much discussion of magical theory in the stories, the implication is there that magic is simply a part of an expanded physics that some organisms can employ.
But for most readers or viewers, warp drive feels different from a flying carpet, and a phaser is not the same as a wand, even if what makes them separate genres is not easily explained. Assume for the sake of the argument that science fiction tries to extend what we currently know about this universe, while magic posits a separate set of rules from the ordinary operating of reality — the spirituals, say, can do things or use things that the mundane do not have access to. That these two look the same if extended to their logical conclusion is just a confirmation that the two naturally belong together under the heading of speculative fiction.
Regardless of the label you put on your genre, if you are writing some variety of these kinds of stories, you do need to understand the rules of your world. Magic, to the author, has to be science. What is possible is less important than what cannot be done. This is to save the author from having an escape hatch in every scene. If the magic can do everything, there is no conflict and thus nothing that the characters — and readers — have to work through. The transporter in Star Trek looks at times like omnipotent magic, and spells in the Potterverse proliferate at the speed of plot, though in both cases, the writers do generally keep things under control. But again, what is not allowed — what does not work or cannot happen — is essential for the author to know.
Do readers have to know? This depends on the point of view characters. The hobbits in The Lord of the Rings see magic performed from time to time and in the case of the One Ring have direct interaction with it, but as Sam finds out when he wears the ring on the border of Mordor, the magic is beyond the ken of halflings, beyond his ability to control. We readers also do not learn the rules, since we experience the story mostly through the eyes of characters who also do not practice magic. Muggles will see wonders, not actions that can be imitated.
But students of Hogwarts are supposed to be learning the hows of magic, and Hermione at the very least should have something to say about the theory. And readers inhabiting these characters will expect to know what is going on. This not only allows them to live in the worlds we create, but also lets us set up surprises that will feel natural, rather than forced, using the rules of those worlds.
As I said above, speculative fiction is not an excuse to be lazy, but is instead an opportunity to create realities of imagination. For the stories to work, these worlds have to have some of the same realization that our world has. The fictional physics, chemistry, biology, and logic must function well enough to sustain the tale.