Gaijin is a Japanese term for foreigners, often considered insulting or demeaning.
In Japanese, gajin is composed of two kanji, or Chinese characters, 外人. Taken individually, these characters mean outside and person, respectively. Another term, Gaikokujin (外国人 lit: outside country person) is considered to be more politically correct, though notably no more accurate if applied to a naturalized Japanese.
Many Japanese, particularly those outside of Tokyo or Osaka, are not aware that gaijin is considered offensive. Recognizing that it is informal, however, they will often say gaijin-san (lit: Mr. Outsider) in an attempt to indicate more respect. In this context, gaijin may be considered analogous to terms such as visible minority or person of colour used in Western countries.
In other contexts, however, gaijin can be used to emphasise a foreigner's non-belonging, and it is this usage in particular that has given the word its racist stigma. Racism in Japan is not given much thought by Japanese because the foreign population is dwarfed by the native population. In contrast to other nations where racism exists, discrimination is often not based on what you are but rather what you are not (not Japanese), which is why gaijin is considered demeaning; it signifies that you are not one of us.
Even Japanese people who have spent significant time outside of Japan can be seen as outsiders, although not always in a negative manner, and as such their names are often not spelled in the typical Kanji but in Katakana, the character set designated for words of foreign origin. A modern example of this is a Japanese-American female artist Utada Hikaru (宇多田ヒカル) who has spent most of her life in New York.