Sanity is a legal term denoting that an individual is of sound mind and therefore can bear legal responsibility for his or her actions. It is generally defined in terms of the absence of insanity. It is not a medical term, although the opinions of medical experts are often important in making a legal decision as to whether someone is sane or insane. It is also not the same concept as mental illness. One can be acting under profound mental illness and yet be sane, and one can also be ruled insane without an underlying mental illness.
Sanity is sometimes used as an engineering term to mean "internal consistency", as in the phrase "sanity check". This has led to pins on integrated circuits being labeled "LOS": "loss of sanity".
Sanity was also the name of a famous Amiga demo group.