Science Fiction is the mythology of the scientific age.
A myth is a story, or account, which tells the truth untruthfully, which is to say, by figures and images rather than literally. For example, the skeptical Greek probably doubted the tale of Icarus was literal, but he knew that ambition, flying too high, caused downfall, especially so in their world of petty tyrants and turbulent democracies, war and betrayal. The tale of the Athenian disaster at Syracuse is just as instructive, but has less story-telling power, than the image of Icarus head high, eyes on the blazing sky, not noticing first one feather work free from its softening wax, then another, lightly floating down the dizzying abyss separating him from the wine-dark sea below.
The scientific age began when ideas of the common man were captured by the findings of science: creation was replaced by evolution, the Ptolemaic universe was made first heliocentric and then (with Relativity) into a cosmos possessing no special center, belief in possession by devils was replaced with belief in possession by subconscious neuroses. Supernaturalism, once the central pillar of the intellectual edifice of the system of the world, was moved to the fringes.
The scientific age also began when the common man became aware that the technological progress of the sciences guaranteed (or threatened) that the lives of his children would differ from his own, due to wondrous inventions like the horseless carriage, the submersible boat, the land ironclad, and heavier-than-air flight. Once his curiosity about the future was piqued, speculations and tales about wondrous inventions and flights to other worlds could be written and sold to him.
I mention the common man here, because while isolated intellectuals may have been aware of the promise and threat of scientific progress as far back as the time of Roger Bacon, not until the ideas and assumptions of the scientific world-view percolated into the collective consciousness, could one sell a scientific romance after the fashion of Verne or Wells.
Let me emphasize that science fiction deals with the myth of the scientific world-view, not the facts of science. John W. Campbell's stable of writers added accurate science to their flights of fancy for the purpose of lending verisimilitude, but it is the mythical image, the figures of science, not the facts, that make a tale SF.
Stories with Time Machines and Faster-Than-Light drives are science fiction, not fantasy, even though the current science rejects the possibility of such inventions. Likewise, ghost stories are fantasy, even if scientific research into ghost sightings is neutral on the matter. The point here is that a ghost story could have been told in Shakespeare's day, or Homer's, because a ghost is a literary device accepted by the audience for the sake of the tale as real, i.e., as realistic. Likewise, the time machine or FTL drive is accepted by the science fiction audience as realistic, even if not real: fantastic inventions are part of the myth of the scientific age.
On the other hand, when Ariosto or Dante or Lucian includes a flight to the moon, they picture a magical voyage to a changeless and spiritual sphere of heaven. The idea that the moon was an orb like Earth, made of rock, perhaps inhabited by material and living beings like us, had to wait for the scientific romances of Wells and Verne to popularize. The idea simply did not exist in the pre-scientific era.
A hard science fiction tale centers its plot on the science or technology; a soft science fiction tale assumes the scientific world-view in the background, and concentrates on other story elements; a space opera is an adventure taking place in a science-fiction-flavored background. Stories with spiritualistic elements are science fiction to the degree that such elements are treated scientifically rather than anthropomorphically. Hence, a psionic boy with telepathic powers due to his mutation is a science fiction character; but a prophet who reads the unspoken thoughts in the hearts of men due to a blessing from the elf-queen, is a fantasy character.
A story is not science fiction that does primarily emphasize the scientific world-view, in the same way that a story is not a western that does not take place primarily in the old west. An SF story with junk science in it (such as the movie DAY AFTER TOMORROW) is still science fiction, even as a story with an historically illiterate portrayal of the Old West is still a Western (such as the movie WILD WILD WEST).
I say "primarily" because a story that had one science fiction element or invention in it would only be slightly science-fictional: the James Bond gadgets do not make him a science-fiction character, because such high-tech gizmos are part of the mythology of the super-spy: the audience is supposed to accept for the sake of the tale that the Pentagon and Kremlin have such gizmos in their secret labs, or SPECTRE or THRUSH on their hidden islands. The WWII and Cold War history of radar, rocketry, the atomic bomb, is how super-science entered the mythology of the super-spy.
Fantasy is a nostalgia for the lost world-view of the pre-scientific age. The governing characteristic of fantasy is that it takes place, not in the real past, but in some setting where the beliefs of the past turn out to be correct. The folk beliefs of the Dark Ages are real, or the pagan gods stride once more down the slopes of Olympus, or Oberon the fairy kind holds court in the Arden wood.
A story where people believe in witches is not necessarily fantasy: a story where Darren Stevens marries a witch, or where Hermione Granger or Sparrowhawl of Gont goes to a school to study witchcraft -- and the magic powers work-- is a fantasy.