I found many questions about how to open the terminal but cant find a question with an answer on how to close the terminal and return back to the desktop of Ubuntu (note: I am on virtual machine)
ctrl + shift + w closes the current tab and ctrl + shift + q closes the entire window.
This is similar to other commands that also are normally ctrl + whatever such as, ctrl + c and ctrl + v for copy and paste which, in gnome-terminal are, ctrl + shift + c and ctrl + shift + v respectively.
I'm not sure if the following works in a virtual machine, however, it is important to also note that when you switch to a tty text session such as tty1 - tty6 using ctrl + alt + f1 up to ctrl + alt + f6, you can return to the regular desktop xsession by pressing ctrl + alt + f7 typically or sometimes ctrl + alt + f8.
TL;DR: Press Alt+F7.
You are apparently asking how to close a virtual console, also known as a virtual terminal--a full-screen text terminal you got to by pressing a key combination like Ctrl+Alt+F1, Ctrl+Alt+F2, and so forth.
In infer this since you say you wish to "return back to the desktop of Ubuntu" (indicating you are not on your desktop now) and, in a comment, wrote:
my terminal in virtual machine is at a black background and when i type exit it refreshes its not a program ...
Rather than actually closing your text-based virtual console, you probably just want to get back to the virtual console on which the graphical user interface is running. This is usually the seventh virtual console, so press Alt+F7. (Ctrl is optional when switching from a virtual console that does not have the GUI running on it; however, you must use it when switching from a virtual console that does have the GUI running on it.)
If those key combinations do not work--or change the virtual console of the host rather than the guest--and your Ubuntu system is a VirtualBox guest system, see How do I switch between virtual terminals in a guest system? as suggested by LiveWireBT.
Another way, which is much less often used, is to run the command