They are both computer code. An application is a piece of software. Not every piece of software is an application. An operating system is the obvious example of a piece of software that is not an application.
"An application" is a piece of computer code that does some particular useful job, such a spreadsheet, a word processor, or a game.
Historically, "application" was used like the word "applied" in the terms "pure and applied math." Pure math is math for its own sake. ("Every map can be colored with four colors.") Applied math is the use of math to solve a problem. When you use a computer to solve a problem you "apply" it to the problem. (A game is an application that solves the problem of entertaining yourself.)
Strictly speaking, an operating system doesn't do anything useful by itself. All Windows does by itself is to boot up and show you a desktop. (Customarily, operating systems "come with" free applications like Notepad or a web browser, but they are not really part of the OS).
Outside of the computer world, "ware" means "something offered for sale," and "hardware" means things like nails or buckets or wheelbarrows. In computers, it is the physical device. When people bought computers in the 1950s they had to pay separately for the hardware and the operating system. The word "software" was coined in the 1950s as a joking way of saying "things you pay for that are not hardware." It is "soft" because it is not physical and because it can be changed. Load a new set of software into a Windows machine, and it becomes a Linux machine.