How to take snapshot and restore a snapshot in VirtualBox 5.2.6

Sometimes you may want to take a snapshot of the current state of your virtual machine (in my case Ubuntu Linux) so that you can revert back to it if anything goes wrong in the virtual machine. The feature in VirtualBox which helps in this is called a snapshot. A snapshot is basically a backup of your virtual machine in its current state.