Format SD Card

Insert the SD Card to format into a USB port of the Raspberry (USB Card adapter needed) and detect which device the card corresponds to

lsblk 
or
sudo blkid

Erase the SD Card by running the following command:

sudo dd if=/dev/zero of=/dev/sdb bs=4096 status=progress

This may take some times. Once completed:

15455776768 bytes (15 GB, 14 GiB) copied, 780 s, 19.8 MB/s 
dd: error writing '/dev/sdb': No space left on device
3777356+0 records in
3777355+0 records out
15472047104 bytes (15 GB, 14 GiB) copied, 802.296 s, 19.3 MB/s

FORMAT WITH FAT32

First create the partition table

sudo parted /dev/sdb --script -- mklabel msdos

Create a partition covering the whole space

sudo parted /dev/sdb --script -- mkpart primary fat32 1MiB 100%

Format the boot partition to FAT32

sudo mkfs.vfat -F32 /dev/sdb1

output will be something like:
mkfs.fat 4.1 (2017-01-24)

Verify everything is ok by running the following command:

sudo parted /dev/sdb --script print

Output will be something like:

Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 15.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  15.5GB  15.5GB  primary  fat32        lba

FORMAT WITH EXT4

Create a GPT partition table:

sudo parted /dev/sdb --script -- mklabel gpt

Create a partition which takes the whole space

sudo parted /dev/sdb --script -- mkpart primary ext4 0% 100%

Format the partition to ext4

sudo mkfs.ext4 -F /dev/sdb1

Output will look like this:

mke2fs 1.44.1 (24-Mar-2018)
/dev/sdb1 contains a vfat file system
Creating filesystem with 3777024 4k blocks and 944704 inodes
Filesystem UUID: 72231e0b-ddef-44c9-a35b-20e2fb655b1c
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

Verify by printing the partition table

sudo parted /dev/sdb --script print

Output will look like this:

Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 15.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  15.5GB  15.5GB  ext4         primary