ChatGPT works by taking in a natural language prompt as input and generating text based on that prompt. It can be used for a wide range of tasks, including generating code, writing articles, answering questions, and more.