Among the numerous formal and informal ways to address relatives, cousins are an interesting choice to show the very different way to express cousins of the same or a different surname, through the difference between the characters 堂 (táng) and 表 (biǎo).
One of the most difficult tasks for students of Chinese language is memorizing the different terms for relatives, as it seems that every tiny difference between two family ties generates a new term, hence remembering all terms is like remembering a small phonebook.
Here we focus on the different type of 'cousins', a single word in English which divided to dozens of words in Chinese. One thing that stands out in such terms is the division to cousins' expressions which begin with the word 堂 (táng) and expressions beginning with the word 表 (biǎo).
堂 most commonly means 'hall' or a special room (such as 课堂 study hall, classroom) but since ancient times it also means 'the same clan' and moreover cousins with the same surname. It is interesting to see the connection between the 'room' meaning and the 'family ties' one. Perhaps the similarity could be expressed through the implication of something enclosed, within, inside and sealed. Members of the same surname are in some way just like a long enclosed hall, continuing one's lineage indefinitely, remaining inside the big metaphoric family house. No wonder then, that 堂 refers to paternal cousins.
表, on the contrary, means 'surface', 'superficial', 'exterior' (among other meanings such as 'list', 'form', 'watch') and in the 'cousin' connotation represents relative ties with no depth. Cousin ties beginning with 表 are those existing mainly through the maternal side of the family. Such cousins, who don't share the same surnames, are 'treated' by the Chinese language as more superficial ties, which in the distant future will not be traced or acknowledged, since the family will be separated.
In imperial times, when marriage between relatives was quite common, the difference between 堂 and 表 relatives was meaningful when it came to choose ones spouses: Marriage between '表' relatives is allowed, while '堂' relatives must not get involved romantically.
Here is a table of the formal Chinese terms for cousins (note that different regions may also use other terms):