A lot of the distinctions made between "Fantasy" and "Science Fiction" are arbitrary, simplistic, and unneccessarily dualistic. One such distinction is that Science Fiction deals with "Science" and Fantasy deals with "Magic".
This definition, of course, is less helpful than it at first appears, even without invoking Clarke's Third Law. Nevertheless, this time around we're going to take a look at what we mean when we use the word "Magic". This is going to be a bit disorganized, I'm afraid, and far from complete; but let's jump in and see where we get.
Magic in Fantasy is often ill-defined; it's just used as a plot device with little thought as to consistancy. Tolkien often seems guilty of this; but, philologist as he is, he suggests that part of the problem may be that we're using a word we don't quite understand. In one chapter of The Lord of the Rings, elf queen Galadriel tells the hobbit Samwise:
"For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word for the deceits of the Enemy. But this, if you will, is the magic of Galadriel."
Gandalf himself is a wielder of powerful magic, but we rarely see him actually do much in terms of flashy spells. This has led to the famous claim that in D&D terms, Gandalf is only a 3rd Level Wizard at best. Tolkien justifies this to a certain extent by observing in one place that the Hobbits as a rule usually only saw his jests and that he rarely displayed his full power. More importantly, Gandalf's mission was to persuade and inspire men and not to be a Big Damn Hero himself.
Unlike fiction, where the author can make things up as he goes along, role-playing games have to have systems of magic worked out in a fairly consistant manner. The best-known RPG system, Dungeons and Dragons, has a idiosyncratic system that's sometimes called "Vancian Magic", because it was inspired by the way magic works in some of the novels of Jack Vance. Under the rules of Vancian Magic, spells must be prepared ahead of time in an elaborate ritual, and once they are cast, they cannot be cast again until the mage once again prepares it. In D&D rules this means that a magic-user must memorize any spells he wants to use at the beginning of the day, and as soon as he casts that spell, he forgets it. Some gamers find this notion silly, and most other game systems find some other means to regulate the use of magic. Still, "fire-and-forget" spell-slinging is one of the hallmarks of Classic Gygaxian Dungeon Fantasy.
Magic as Science
One theme that comes up occasionally in fantasy is the idea that Magic and Science are antithetical to each other because Magic is irrational while Science is based on Reason. Personally, I don't care much for this trope, because it seems to me that if Magic works at all, it has to have some kind of rules which it follows, and which can be understood.
L. Sprague de Camp wrote a novella entitled Land of Unreason about a 20th Century man who finds himself transported to fairyland. At first he considers this world a "Land of Unreason" because nothing seems to make sense. But as he figures out how things in the fairy realm operate, he realizes that there are indeed rules here; he just needs to figure them out.
James Robinson touched on this in an issue of his STARMAN comic book. In one story, the Golden Age Starman, Ted Knight, has to find Etrigan the Demon. Now Knight is a scientist and a skeptic. Someone asks him how he can deal with a demon when he doesn't believe in magic. He replies that he works on the same team as Dr. Fate and the Spectre; he's seen them do things he can't scientifically explain, but he doesn't believe they are inexplicable. As far as he's concerned, what they call "magic" is a form of energy; and if energy exists, then science can devise a means of measuring it. So he builds a device to detect "magic" and uses it to trail the Demon.
Sufficiently Advanced Technology
Arthur C. Clarke, in his "Third Law", states that "A sufficiently advanced technology is indistinguishable from magic." We get this in the old Great White Hunter stories in which Alan Quatermain or someone impresses the superstitious natives with the "White Man's Magic" by dropping a deer with his rifle. Looking at it from the other end, one of the villians from the comic book THE FLASH is a stage magician from several millenia in the future named Arba-Kadavera, whose magical-seeming powers come from futuristic gadgetry.
The early issues of Jack Kirby's THE DEMON has a similar theme. Etrigan the Demon is a servant of Merlin, fighting against the machinations of Morgan le Fay; but the way Kirby drew the comic, the magical stuff all looked like alien technology. Of course everything Jack Kirby drew looked like alien tech; but I think in this case it was intentional; that in Kirby's vision the sorcery of Merlin and Morgan really was a sufficiently advanced technology. Later writers of the character dropped this aspect and emphasized Etrigan's hellish heritige; but I kind of like the techno-magic vibe of the first issue.
Perhaps the most interesting variation on this theme I've come across is in a novel entitled Newton and the Quasi-Apple by Stanley Schmidt. Anthropologists visiting a planet with a medieval technological level hope to spark people's interest in science with a type of fourth-dimensional matter that behaves in a non-euclidean manner. Unfortunately, one of the natives actually has started to suss out some basic principles of gravity and motion, but the stranger's demonstrations have discredited his discoveries.
Keep in mind, though that the inverse of Clarke's Law is just as valid: That a sufficiently advanced Magic is indistinguishable from technology.
Numbers have always have magical connotations. Pythagorias helped develop geometry; but he also believed in the mystic properties of numbers. Throughout history, numbers have been used for symbolic purposes. The Bible is full of them. As the science of Mathematics developed, mathematicians also developed the idea that the whole world could be described mathematically. And so it was inevitable that things would come full circle and someone would try applying mathematics to magic.
L. Sprague de Camp and Fletcher Pratt wrote a several stories, many of which were collected as The Incomplete Enchanter, about a modern-day mathematician named Harold Shea who discovers that interdimensional travel is simply a matter of getting the math right; but when he finds himself in other magical worlds, he must figure out the laws by which the magic of each world works in order to survive.
More recently, The Atrocity Archives by Charles Stross and the other books of his Laundry series is about a secret government agency that uses technomagic in a world where higher mathematics can weaken reality, and where computer programming really is an arcane skill.
Another idea that comes up in legend is that knowing the True Name of a person can give you power over him. Usually this only applies to demons and certain types of magical beings; but some writers have expanded this idea to suggest a system of magic based on knowing the True Names of things. A Wizard of Earthsea by Ursula K. LeGuin uses this type of magic system.
Granny Weatherwax, one of the recurring characters in Terry Pratchett's Discworld novels, subscribes to a specialized form of magic she calls "Headology." She holds that most of the business of being a professional witch has less to do with spells and arcane forces than it does with giving people what they expect and letting them see what they want to see. Which isn't to say that she can't use more traditional forms of magic; she can and does. But convincing someone else that you already have saves a lot of bother.
Let's Make a Deal
Sometimes the magic weilder draws power not from himself, or even from the world around him, but from other, more powerful allies. The medieval Christian view of the sorcerer was one who gained his powers from demonic forces: as Faust did with Mephistopheles. But the powerful forces don't have to be evil. The Bartimaeus Trilogy by Jonathan Stroud is set in a world where magicians can conjure djinni and compell them to do their bidding. Similarly, Jonathan Strange & Mr Norrell by Susanna Clarke is drawn from faerie and involved dealing with the dangerous, chaotic beings of that realm. But the problem with getting your magic from other beings is...
There's Always a Cost
Neil Gaiman's graphic novel The Books of Magic is about a young English boy with tossled dark hair and glasses who may be the greatest magician of his generation and who is not named Harry Potter. A quartet of mystic guides takes him of a tour of the magical world. On one level, the story is a series of encounters with nearly every magical character in the DC Universe; but more importantly it is as exploration of what Magic means. The protagonist, Tim Hunter, gets many answers to this question -- many of them conflicting -- but one thing is pretty constant. Pretty much everyone he talks to agrees: you always have to pay something. Magic always comes with a cost of some sort. This is an idea Gaiman has carried over into many of his non-comics works as well.
The anime series Full Metal Alchemist explicitly states this at the beginning of each episode. It is set in a world in which Magic has been reduced to a science which in the series is called Alchemy. The First Law of Alchemy is that for every magical action, there must be an Equivalent Exchange. The story begins when a young alchemist named Edward and his little brother Alphonse rashly attempt to bring their mother back from the dead. They grossly underestimate what would be needed to balance the equation and the resulting misfired spell destroys Al's body and nearly costs Al his life. It is only by quickly casting another spell, at the sacrifice of two of his own limbs, that Ed is able to save Al's spirit by anchoring it to a suit of armor. Much of the rest of the series involves Ed's quest to restore his brother to his proper body.
Odd, isn't it? One of the underlying impulses behind man's dreams of magic is the desire to get something for nothing. But perhaps the most satisfying tales of magic teach us the exact opposite; that, as Heinlein taught us, There Ain't No Such Thing As A Free Lunch.
Which brings us back to Science Fiction. Funny how that worked out.