From the author of htops answer How to calculate system memory usage from /proc/meminfo (like htop)
I got to know that the total memory in htop is calculated from /proc/meminfo. I think I could crosscheck this in code as well and it checks out. However compared to memory bar in htop. I see a major difference in the memory values shown in /proc/meminfo.
In my /proc/meminfo the memory consumption reads
MemTotal: 4144807288 kB
MemFree: 3513532764 kB
MemAvailable: 3936769368 kB
Buffers: 1119392 kB
So the Total used memory , which I think represented by the memory bar should be MemTotal-MemFree in GBs which should be (4144807288-3513532764)/1024^2=602Gb as far as I understand.
However for me this value shows almost 180Gb. Could anyone explain how the values in /proc/meminfo and one in htop would become different.

Let me first say holy moley that's an insane amount of RAM.
Anyway, there's something not being understood here:
"Memory free" is totally unused memory.
"Memory available" is the amount of memory that's totally unused ("Memory free" above) + memory that could be freed in an instant if the kernel dropped its file system caches. Generally, available memory is the stat you should look at / care about.
Using the "Memory available" stat in our calculations instead, let's calculate:
Much closer to the 180G
htopdisplays as the amount of "used" RAM.Try also running
free -hand look under the "available" column.