First of all, start the command prompt as administrator. Do that by pressing the windows-key and type in cmd. Then, press Run as administrator.
Now, type in diskpart and press ENTER.
This should look like this:
To show all the drives connected to your computer, use the list disk command.
To select your desired disk, use select disk <number-of-your-disk>.
To determine which disk is the one you want to format, you can look at the size of each disk.
I chose Disk 2 as that's my 8GB USB drive I want to format.
Make sure you have the right disk selected. If you use the following command on the wrong disk, all the data stored on it will be lost.
Before formatting, you have to delete all the files on the disk. Do that by typing in clean with the right disk selected.
To make the disk accessible again, you have to create a primary partition. Do that by typing in create partition primary.
Now, you can format the disk. To do so, use the command format fs=fat32. You can also use format fs=fat32 quick to do a quick format.
Instead of formatting your disk in FAT, you can also choose to format in NTFS. Just replace fs=fat32 with fs=ntfs.
NTFS: only supported by windows operating systems, max file size: 256TB.
FAT32: supported by many operating systems, max file size: 4GB.
Finally, assign the formatted drive a letter. You can automatically let windows assign a letter by just typing assign. To specify a letter, use assign letter=# (replace # with whatever letter you like).
Now you have successfully formatted your disk via diskpart.
To exit diskpart, just type exit.