The full form of CGI is Common Gateway Interface. It is a set of standards that define how information is exchanged between the web server and a custom script.
The Common Gateway Interface is a standard for external gateway programs to interface with the server, such as HTTP Servers.
Do you know what happens when you click any of the link on the web page?
I mean your browser contacts the HTTP web server and demands for the URL that is the file name and the web server passes the URL and looks for the file name and if it finds that file it sends back to the browser otherwise sends an error message indicating that you requested a wrong file.
And then the web browser takes response from the web server and displays either the received file or the error message.
However, it is possible to set up an HTTP server so that whenever a file in the certain directory is requested that the file is not sent back instead it is executed as a program and whatever that program outputs it send back to the browser to display.
So this function is called the common gateway iterface or CGI.
And programs are called CGI scripts.
These CGI scripts can be a python script or a PERL script or C++ program.