Before you start downvoting, this is a more nuanced question than it seems, yes we can tell ~~Isaac Asimov~~ the foundation apart from ~~C.S. Lewis~~ Narnia and clearly box them into the Sci-Fi and Fantasy respectively.
So what if we take something like Star Wars? Well, it's set in space and its got cool tech and laser beams and stuff. Well it's not really sci-fi it's High Fantasy, Space High Fantasy, it's about space wizards and gizmos that are practically magical (see kyber crystals).
So warcraft? Well that's as nerdy as it gets and sci-fi is nerdy, I'd also class it as space fantasy. Well, what about Dune? It's similar to warcraft with the space human empire and the superpowers and stuff, well Dune, despite having some "fantasy-like elements" falls into sci-fi.
Horizon Zero Dawn, Super-hero media, the Coldfire trilogy, Dragon Riders of Pern, and other works blur this line while falling into one camp more than the other.
Sci-Fi and Fantasy are sister genres, simmilar and yet different. It's not just a distinction of pew pew pew vs klink klink shlash.
So what distinguishes one from the other?
Well, let's start at the beginning, at their origins:
SCI-FI:
Arguably the first work of Sci-fi is Frankenstein by Mary Shelly. This book explores the theoretical potential of the groundbreaking scientific advancements of the time, it explores big questions of ethics, and the human condition and tries to keep itself grounded in certain rules from our world while bending them based on current scientific knowledge.
Sci-fi was born from the Romantics (that's capital R Romantics not romance), so it comes from a rejection of materialism and empiricism. It asks, "How does all of this progress and knowledge affect us as people?".
While Frankenstein wouldn't be classed as "Hard sci-fi" it sticks to its rules and this human perspective can be seen across the genre from cyberpunk like Do Androids Dream and Snow Crash, to soft sci-fi like the martian chronicles and stranger in a strange land, and even in hard sci-fi like the Martian and Gattaca. Sci-fi has always been concerned on these big questions:
"What does it mean to be human?" "What makes a person a person?" "What problems can arise from this technology and how should it be used?" "What is our role in the universe?" "If we can do it, should we?" These are the pressing questions in any sci-fi story, going back to Frankenstein all the way to iRobot and beyond.
Sci-fi is the genre of questions, it takes the audience on a journey where they are encouraged to question their existence, to tackle the status quo and conventions about morality or society and topple them through the reader's big brain. It leaves the audience thinking about what they just experienced and it can leave them feeling uncomfortable.
In scifi we take what you know and push it as far as we can until the thing is no longer what you thought it was. We question everything until it leaves us with some answers but leaves the answers that really matter to the reader.
​
FANTASY:
So fantasy... well it doesn't have a clear-cut initial date, some people credit George MacDonald with the genre with Phantasates in 1858. But you could argue that Arthurian literature falls into the earliest form of written fantasy. But I'd say it goes even further, Fantasy isn't as clear-cut (while yes you could argue that Frankenstein isn't the first sci-fi story and that the first one was a True Story by Lucian of Samosata https://en.wikipedia.org/wiki/Lucian I say to you "STFU").
In my personal opinion, fantasy isn't a genre that was born of a single work, it came about as the natural evolution of folklore and mythology. The fantastic stories humans have been telling for centuries culminated into fantasy, stories of fay, princesses, and knights, from myths, legends, and fairy stories it became fantasy.
So is fantasy just about the fantastical? Well yes and no. It also has to have some aesthetic and narrative beats that makes said story fantasy. You could take something like Black Swan and say hey this is fantasy, it draws inspiration from folklore, it has a lot of fantastical elements, why is it not Fantasy? Well it doesn't have the aesthetics of it, it is aesthetically a psychological thriller and it treats its characters as such.
Well, what is the Fantasy aesthetic, then? Big Castles, elves, swords, and sorcery? Well no, while high fantasy works such as the Lord of the Rings have given this idea, and it has permeated throughout the genre there exists several genres such as Urban Fantasy and the aforementioned Space Fantasy.
So what do Percy Jackson, sandman and the Witcher have in common, and why do we group them in the same box?
Fantasy has in my opinion three key characteristics:
1. The rules of the world are flexible: while the author can impose unbreakable rules or a strict magic system the author decides what is and isn't possible. 2. Magical elements: even if there is no magic in the story, there is still a sense of magic, the act of turning something mundane into something magical without it being magic or turning something magical into something mundane without it becoming mundane is the real magic of fantasy. 3. The main focus is not the content of the story but rather how the story is told: so here is where I think Fantasy shines the most, since I've already classed it as an evolution of myth-making and classic human story telling traditions, it makes sense that it often experiments with how the story is told since that is the main focus of fantasy, its story telling above all else. While it can make an argument like scifi and ask questions its main focus is story telling. LOTR challenged convention by making an entire history of a world, witcher by telling real adult stories in a fantasy setting, sandman (and anything by Gaiman) plays with story telling every other issue, Percy Jackson plays with retelling old stories and applying a modern context.
Suming up I'd say as opposed to sci-fi, fantasy isn't a genre of big questions, while it can explore it the point of fantasy is to tell a story and for the reader to lose themselves (that's literally every literary genre dumbass).
In Fantasy we take you to a new world, familiar or bizarre we will travel through those lands and let our imagination run wild, get lost in the forests of dreams and nightmares, make our own way through the caverns of convention and traverse a new line down a snowey mountains alongside others who have done the same. While there may be many stories like ours, ours will be unique as we embark on our quest.