There are two steps to install Windows 8/8.1: create the installation media used to install Windows 8/8.1, and the actual installation process.
First, download Windows 8/8.1 from Microsoft's website: Downloading Windows 8
Once you have the download, you can follow the instructions on Microsoft's website to make the installation media and install Windows: Installing Windows 8. Scroll down to the bottom, where it says "Clean install of Windows 10 using installation media".
NOTE: The instructions in this article are for Windows 10, but the process is the same.