There are a lot of words that basically means Chinese (language) and can usually be used interchangeably but do convey subtle differences in meaning and situations.
1.中文 (Chinese language)
The most popular one. Can be used in almost any situation.
2.汉语 (Han Chinese language)
Prominent in academic and formal circumstances. Also used by people who prefer a more formal style.
But it is focused on the spoken part. When you are specifically referring to the written script, 汉字(Chinese characters) is used instead.
汉字 as a form of writing is also used in some other languages. In this sense, do not use 中文.
3.国语 (National language), 华语 (Hua language), 普通话 (Common Tongue)
All the same thing, namely Mandarin (官话), but used by different people. 国语 is used in the Republic of China (Taiwan), 华语 in Southeast Asia by ethnic Chinese immigrants, and 普通话 in the Republic of China (mainland China). They are as different as Received Pronunciation and General American Accent are.
On the other hand, 中文 and 汉语 includes 粤语 (Cantonese) and other dialects of Chinese(some would say they are languages in the Chinese language family).