|First appearance||12: Poisson|
Black Hat is a stick figure character in xkcd. He is distinguished by his eponymous black hat. In his earliest appearances, Black Hat wore a taller top-hat style hat, that quickly evolved to have the current shape and style of a pork pie hat. Judging by 1139: Rubber and Glue, he has worn the hat since he was a child. Within that strip, a young Hairy also gave him the nickname "Hatboy". Black Hat seems to have short hair, as shown in "Journal" series, 412: Startled and 1401: New. He is revealed to be a blogger in the Secretary series, when Cory Doctorow referred to him as "one of our own". Unlike many other characters in xkcd, he seems to represent the same character in every appearance.
As stated in the title text of 29: Hitler, "the hat guy" is based on a character named Aram from the now-defunct webcomic Men in Hats. Like Black Hat, Aram seems to have frequently made judgmental, insulting or controversial comments in a very emotionless manner. This may also have been the comic where Black Hat truly comes into existence for the first time. He appears earlier in numbering with 12: Poisson, but that was actually first released more than a month later, and put up onto xkcd together with all the old LiveJournal comics when they were re-released on the new xkcd site. Then there is also 24: Godel, Escher, Kurt Halsey, which were released a good month earlier (and drawn during an 'unending Nasa lecture'), so the oldest with a possible Black Hat. But here Black Hat does not really resemble his later appearances.
It's not verified that Black Hat is a reference to Black hat hacking, but the character's personality is in line with the idea of a "black hat hacker" from the software engineering culture that Randall's comics are written for. Black Hat speaks from a place of casual power and safety, living in the luxury that many early hobby hackers found by being ahead of the tech curve or even actually hacking financial systems, hatching evil schemes often for no reason other than to cause chaos or go against the societal norms. He has found a female counterpart and partner in Danish. While no definite reason is given for how he became so sadistic, in 792: Password Reuse Black Hat says "since March of 1997 I don't really believe in anything" suggesting some traumatic experience made him this way. Some black hat hackers are simply so detached from the real world they don't understand that others suffer; others may have led rough lives and been through crime rings as a sole way to find community. In 1139: Rubber and Glue, the boys making fun of Black Hat as a child appear to be in elementary school based on one calling for his mom, so Black Hat probably is too. He is already sadistic by this point so the event would have happened when he was quite young; experiencing it so early would explain how the mystery event could have reshaped his entire personality. Unfortunately no details are ever given.
Black Hat's hat appears white in 1005: SOPA due to the colors being inverted. (Black Hat is only visible by manipulating brightness and contrast.). A "white hat" is a hacker who uses their advanced skills to keep the norms, prevent chaos, and protect people.
In his talk at Dartmouth  Randall discusses his reasoning behind creating a separate "asshole" character in his comics, or a classy asshole, which his friend Beth coined Classhole, as mentioned in the title text of the comic of that name, where Black Hat describes how he aspires to become just such a Classhole.
It is possible that Black Hat has a name that has been used in the actual webcomic, as opposed to the name "Black Hat." In the title texts of 29: Hitler and 493: Actuarial, Black Hat is referred to as "the hat guy" and "Hat guy" respectively. In 1139: Rubber and Glue, Black Hat is referred to as "Hatboy". These early characters may also be a different persona.
- Actually the first comics to be released using Black Hat is not number 12, 12: Poisson but 24: Godel, Escher, Kurt Halsey because the latter was released on LiveJournal (as number 6), where Poisson was first released when going over to xkcd. See details in the trivia for both Poisson and Godel, Escher, Kurt Halsey.