In the old days Teletypewriters were typewriters that translated what was typed locally on a mechanical typewriter into EBCDIC or ASCII codes and then transmitted over a cable to a remote computer. Hence the prefix "tele", which means "at a distance". The word "terminal" was sometimes used, because the teletype was the terminal end of the wire where data was entered and transmitted to the computer or receiving station. Each "tty" device was connected via a serial port, because copper wire was expensive and so "parallel" port devices were mainly used for short-distance interfaces like to a local printer. This is before wireless networks were widely used. In the old days of multi-user computer environments you could have multiple "terminal devices", i.e., 'tty' devices connected to the same central computer. This is the original hardware environment in which Unix was developed. That hardware legacy is still with us in the naming of the software components in the Linux operating system.
Today in Linux, the tty is a legacy name used to refer to the user interface for text-based input and output, otherwise known as a "terminal". In Linux systems, there can be multiple tty device "consoles", to support potentially dozens of serial ports or more. tty0 is the current one in use, but Linux allows you to switch to another session by changing to a different tty, e.g., tty1. Linux (e.g., Ubuntu) supports up to 6 ttys by default, but this number is configurable.
In practical terms, think of a tty as a serial communication channel that a Linux session uses to communicate with a user.
How it works is that there is a parsing process bound to the tty session that parses the user's input and passes valid commands to the computer to execute.