This happens often enough: someone will quite casually characterize this or that behavior as sane, or as insane, and out wags the other wag's tongue: "Define sane." As if it can't be done.
In a mocking tone! As if this is impossible - to define sane. As if it's a challenge! They toss it clap on the counter like a gauntlet. As if it's alllllllllllll relative, and therefore, you can't define it, buddy!
Asked to define sane, I always say "Sure!" I'm happy to.
There are two components that go strongly into what people call "sane": what you see, and how you act. Obvservation, and response.
Sanity is the ability to see reality and act appropriately. Observation: your ability to see reality. Response: your ability to act in ways that benefit your health, life, goals and well-being (and the well-being of those whose good outcomes you've bound up in yours).
That's it. Simple as that! See reality, act appropriately. You can stop reading right now!
Meanwhile, I'll go on to delve into two main ways we characterize sanity, but really, the one is only an extension of the other and both break down into observation and response.
Sanity, the social definition.
Are you able to see the same reality others see? If your mindset, viewpoint, picture of reality converges quite closely upon the observable reality seen and ratified by those others around you - the general functioning public, those generally accepted-as-sane - congratulations! You have a "leg up" on being accepted as sane. But you're not 100% home-free: next you must also be able to see, understand, internalize the various ranges of accepted response to this shared reality. Observation of shared reality, together with a shared understanding of acceptable responses to it, constitute "sanity" as far as the social definition goes.
Note, we talk about "response," but in the social realm, actually acting in the acceptable way isn't mandatory. Cf. Robin Williams. As long as you can demonstrate you see what others see and you at least know what you're supposed to do - this demonstrates sanity.
The social component is entirely scalable. If there are only twelve of you on a desert island, with no recourse or reference to outside standards, then sane is whatever this small society agrees. If your immediate society is in touch with the wider world and wishes to submit itself to what "the world" considers sane, it will not lack for benchmarks there. However wide the aperture your society sets, to be judged sane, you need to be able to see that same reality, and understand what response is acceptable to it.
None of this makes sanity a squishy or relative concept. The details of what a given society sees as real and sees as sane may differ - and so? Inconsequential. Sanity remains universally the same in all societies: you are able to see society's reality, and you are able understand society's acceptable range of response to it.
Sanity, the survival definition.
More basic, and even easier to break down. As with the social definition, sane observation and response reduce to: see reality, act appropriately. But here, there is no intermediary or judge to consider, to line up with; no ratification required from society and no feedback except the direct feedback from reality that your actions prompt. Alone in a wilderness (as we all are from time to time), you must see the actual reality that impacts, attacks, benefits you. And you must be able to understand what outcomes result from your actions, judge your actions and adapt your behavior to produce better outcomes, reduced risks of damage. This is sanity in action, a direct and appropriate response to one's environment clearly-seen.
Of course in general, for humans, the basic survival definition of sanity involves a great degree of accommodation with a social reality. Or else if not, it involves getting the hell out of that society's sphere! People do that shit all the time. It's totally an acceptable and mainstream thing to do. They even write books about it!
Sanity in its social definition is only as healthy and good for you as that society is.