Some tarballs have no top folder. You unpack one in your Downloads folder and fifty files land next to everything else. I’d rather not clean that up by hand, and GNU tar has a flag for it.
tar -xzf archive.tgz --one-top-level
Without a value, tar creates a folder named after the archive, minus the compression suffix, and extracts into that. With a value you pick the name yourself:
tar -xzf archive.tgz --one-top-level=mydir
Here is what it did with an archive whose two files had no folder around them. The archive was called bomb.tgz:
$ tar -xzf bomb.tgz --one-top-level
$ ls -R .
.:
bomb
./bomb:
one two
With --one-top-level=mydir the same files ended up in mydir instead. It combines with -C, which picks where the new folder is made: tar -xzf other.tgz -C ~/work --one-top-level creates ~/work/other. If the archive is unknown to you, list it first with tar -tf and see whether it has a top folder at all.
Caveat: if the archive already has a folder inside it, you get a folder around that folder. On GNU tar 1.35 a file called other.tgz that contained proj/ unpacked to other/proj/. To drop a folder you do not need, use --strip-components instead. The flag is GNU tar. The tar on macOS is bsdtar with a different option list, so I’d check man tar there first.
Further reading: GNU tar manual