How chat (IRC) and messanger (IM) services work
wikipedia IM article

Chat and messenger services work using a range of different protocols. IRC internet Relay came first and the newer Instant messenger services are built on similar technology.
IRC uses a channel system were a particular "conversation" takes place in real time. A bit like an online walkie talkie. Useful for technical or specialists conversation when people may be physically remote, but as anyone who has watched the news recently knows open to abuse. The may drawback is that under certain circumstances It can be difficult to know who you are talking to. True IRC systems do require some special chracters to be typed ans so were often the domain of computer nerds.
Whilst on line people use an alias (sometimes called an avatar if it associated with an image). Users join a conversation often reffered to as a "room".

Both systems IRC and IM rely on a client - server model to operate. Client software is run on the user machines with a web based server maintaining the covversation as a "channel"in real time.

The microsoft messenger system is probably the most common type of Instant Messanger (IM) it uses its own protocol and so to use its users need to install a different piece of software to use the services. Other big players are Apples Ichat with AOL, Google and Yahoo all offering similar services.
How Chat and IMs work
IT would pe possible to get very techy here but basically each converstion or room is called a channel. The server "ehoes" each new line of text to all the computers (clients) connected to a particular conversation. As this happens very fast you have the illusion of a real time conversation, there will actually be some lag but not enough to be a barrier to communication. With Instant messangers the users control who can be in a particular conversation and so these systems are less public but still open to abuse.
Nearly all Instant Messenger services have an enhanced set of features. They add support for individual conversations with a list of contacts. From your contacts list you can also see who is online at a particular time and you can have a global conversation like in a chat room. On many you also get support for attachments in real time (subject to your connection speed). Finally they are oftenintegrated with webmail system so you can contact offline contacts as well.
At the moment there are a few big players in the Instant Messenger market all operating different protocols. There is a standard called Jabber which allows connection to other protocols which is gaining some ground but we are a way from one Instant messanger protocol having control and letting us all talk to each other.