For example, let's say that you wanted to "hook up" your Unix database to the World Wide Web, to allow people from all over the world to query it. Basically, you need to create a CGI program that the Web daemon will execute to transmit information to the database engine, and receive the results back again and display them to the client. This is an example of a gateway, and this is where CGI got its origins. Common functions perfromed by a CGI are Forms Processing, Animation, DataBase Access, etc.
The database example is a simple idea, but most of the time rather difficult to implement. There really is no limit as to what you can hook up to the Web. The only thing you need to remember is that whatever your CGI program does, it should not take too long to process. Otherwise, the user will just be staring at their browser waiting for something to happen.
Basically speaking, a CGI is a script or program written to handle functions that cannot be performed by plain old HTML tags.
Most CGI's are written as shell or PERL scripts, or C programs. Shell and PERL CGI's are commonly referred to as scripts because the commands are listed in a plain text file. CGI's written in C are commonly referred to as C programs, because the CGI must be percompiled into an executable program before it is used.