Installing OS without optical drive

So I've heard it is possible to install windows or any OS for that matter with a flashdrive but how do you actually do that? I'm building a new rig but if i could save the 20 dollars and not buy an optical drive and just install my OS from a flashdrive that would be cool.

I don't really use windows but in Linux you just use the DD command or use Unetbootin if you like a GUI

Some one else will have to the Windows side.

Windows is quite easy. A quick Google search, something like "Installing Windows without Installation Media" should get you going.

Microsoft offers a tool for free which downloads the ISO and mounts it to the USB drive for you. 

Basically you just download the .ISO of whatever Windows version you want and use a tool to mount it to a USB stick if you wanna do it manually. 

Then simplytur your PC off. Stick the USB drive in and turn it back on. If there is no OS on the HDD it should boot directly from the USB stick automatically. If it doesn't then spam whatever key on your motherboard allows you to open the boot selection menu and select the stick.  Otherwise go into the BIOS/UEFI and change the boot priority to USB. Just remember to change it back when you're done. 

From there it is just a few clicks to install Windows 8 or 7. Click fresh install. Put in your key. Partition the drive and wait a few minutes. Reboot and you're done. Depending on the speed of your drive it can take as little as 5-10min. 

Seems simple enough, thank you very much

Yeah, M$ has the windows bootable usb creator:

http://www.microsoft.com/en-us/download/windows-usb-dvd-download-tool

Easy to use, works fine.  Used it myself on more than one occasion.

If you want to create a bootable Linux usb drive (from windows), then the universal usb installer works great:

http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/

It's generally what I use whenever I am going to do a fresh install.  If your doing an install on older hardware (say, 10 years old or more?) though, a lot of times they wont play well with standard bootable flash drives.  In that case, Rufus is the way to go:

https://rufus.akeo.ie/

Just make sure to select the "Add fixes for old BIOSes" option under "Format Options", and it should boot fine on older systems. Hope that helps.

Use win32disk imager works for all ISOs