Hard drive
A hard drive records data (text, images, databases, software) on a magnetic platform. Originally independent peripherals, a desktop PC, tablet and smartphone will usually have one built in, that is where the operating system resides, you can expand storage with external drives attached to a hardware port, the main way peripherals are attached. This is the same technology used by cloud services.
Other technologies have partly replaced magnetic hard drives in consumer products: read-write optical drives (CDs, DVDs, and BluRay discs use this technology), and using RAM circuits to act as memory, thus producing memory sticks and solid state disks. These are usually more expensive than rotating drives but have faster access and reliability because they have no moving parts, and therefore are less susceptible to catastrophic crashes, laptops, smartphones and tablets use solid state disk drives to store data because of their small size, reliability and low power consumption.
Forensic analysis
In an operating system there are always temporary files and logs created all over the place. Every time you open a document, view a picture or watch a video your operating very often creates a temporary copy in another part of the drive that is not visible to you but it will be found with specialist forensic tools, even with the browser in Private mode something could be left behind.
You can download programs like CyberScrub that claim to carry out military-grade erasure of all data, including temporary files, by overwriting it with multiple passes of a random algorithm or zeros and wiping hard drive free space, this makes it very difficult or impossible to recover the data but depending on many factors, like how good the software is, your computer unexpectedly crashing or permissions stopping data erasure, sometimes the software might not erase 100% of everything left behind. Another caveat of secure data erasing is that you don´t have the time to run the software every single day and if you lose your laptop it could be that the last time you securely erased the data was a week ago and every single page you visited and file you viewed will be found. Another common problem is that although the file can not be recovered, often the file name can still be read and this could be telling of the kind of file you viewed.
One good way to secure your operating system is by fully encrypting it with a tool like VeraCrypt in Windows, Linux and Mac have different software that can do that. If for some reason you can´t encrypt your operating system and you care about privacy you should still use Private mode in your browser and use software to securely erase data but always bearing in mind that this might not be totally effective, learning how full disk encryption works it is well worth if the leakage of the personal data you hold could lead to life changing situations such as a divorce or financial ruin. There are also differences in between how data must be securely erased in a hard drive with plates, a solid state disk and a hybrid disk, with technology changing everyday day, the software that promises to securely wipe data is could not be effective.
Another excellent way to thwart a forensic analysis of your hard drive is by using a live operating system that runs in RAM such as Tails, for this you will need a USB thumbdrive, burn the Tails operating system in the USB and boot your computer from the USB drive, the instructions to do this can be found in the Tails homepage. When you run an operating system all in RAM logs are still created but as soon as you switch off the computer everything is going to be irrecoverable for ever because nothing was written on the disk to start with, your activities run in volatile RAM memory, or you can have a computer without a hard drive and run your operating system using a DVD where writing data is impossible, the caveat is that if you wish to save a document you downloaded you will have to do so in an external device as saving it to the operating system will be impossible since it resets to the original state everytime you reboot the computer.
Encryption
Data on a storage device can be encrypted, that is requiring some kind of password or similar to decode. Encryption is a major military topic. Both sides - as in World War Two - struggle to come with up with an encryption protocol that the other side can not figure out how to decode.
Briefly, the longer the passcode, the more protected the data is; it would take more time to try every possible code, what cryptographers call the "brute force" method. This is in essence the technique used by PGP]] (Pretty Good Privacy) and many commercial encryption applications, who may claim that their protection has never been broken, which is true but not cause for relaxation. (in military applications it's more complicated, there may be a separate passcode for each character, as in the Nazi's Enigma machine, which the Allies decoded thus changing the course of World War Two. See the Wikipedia article.)
The government is not going to use a brute force method on you. It is too resource-intensive, and incredible as it seems, there are on the other side some who are sane enough to think it's more important to use their finite resources to go after terrorists rather than individual boylovers, girllovers, family lovers, or child porn collectors. There are too many of them, and the authorities have all the cases they can handle using other methods. These include other people informing on you, financial records (money can always be followed), ISP logs, analysis of Internet traffic, etc.