One dictionary entry, two related senses
The Pukui & Elbert Hawaiian Dictionary, compiled by Mary Kawena Pukui and Samuel H. Elbert and still the field's standard reference, lists mahalo as a noun and transitive verb (nvt.) with two senses under one entry. The first is thanks or gratitude, and to thank: mahalo nui loa, "thanks very much"; ʻōlelo mahalo, "compliment"; mahalo ā nui, another way of saying "thanks very much." The second is admiration, praise, esteem, regards, or respects, and to admire, praise, or appreciate, illustrated in the dictionary with ʻo wau nō me ka mahalo ("I am, [yours] respectfully") and its own worked example ka mea i mahalo ʻia, Mr. Pākī, glossed "the esteemed Mr. Pākī."
Both senses share the same underlying idea rather than being two unrelated words that happen to look alike: mahalo names a positive, appreciative regard for someone or something, and English splits that single feeling into "thanks" (regard for an act) and "admiration" (regard for a quality) where Hawaiian keeps it as one word. That is also why mahalo works as both a noun and a verb without changing form, typical of Hawaiian, which marks far less on the word itself than English does and relies more on word order and context. A single loanword doing work English fragments into several is common wherever a short borrowed term crosses over whole: Arabic's habibi covers a comparably wide stretch of affection and address that English splits across "dear," "honey," and more, depending on who's being addressed.
The root means "admire," not "thank"
POLLEX-Online, the Polynesian Lexicon Project run out of the University of Auckland and the Max Planck Institute for Evolutionary Anthropology, traces Hawaiian mahalo to a reconstructed ancestor at the Nuclear Polynesian level, *masalo, glossed simply "be astonished at, admire." The "thanks" sense that dominates mahalo's modern use isn't in that root gloss at all; it's a meaning the Hawaiian reflex picked up on its own, with the admiration sense as the closer match to the ancestral form. The same root shows up, more faintly, in a couple of other Polynesian languages: New Zealand Māori has mīharo and the related maaharo, both meaning "to wonder at, be amazed, admire." Tahitian has a possible cognate, maharo, glossed as an emotion (anger, desire) subsiding rather than as admiration, but POLLEX itself flags the connection between the Tahitian form and the rest of the group as an uncertain semantic match, not a confirmed one.
There is a second, separate Polynesian root that happens to look almost identical: *masalo at the older Central Pacific level, glossed "think about, consider, suspect." POLLEX records this one in East Futuna (masalo, "think, be of the opinion that") and East Uvea, whose reflex is spelled mahalo, identical to the Hawaiian word, but glossed "to think, presume, suspect, conjecture." That East Uvea mahalo and the Hawaiian mahalo this article is about are not the same word reaching two islands; they're two different Proto-Polynesian roots that happened to converge on the same modern spelling, one meaning "admire" and the other "suspect." English kept only the "thanks" half of mahalo's own sense once it borrowed the word into tourist-facing use, the same kind of narrowing that happened when English adopted schadenfreude rather than translate it: the loanword survives, but usually carrying less of its home meaning than it started with. Hawaiian's other widely borrowed word follows a similar pattern of the English version covering less ground than the original: ohana means family in everyday English use, but the Pukui & Elbert dictionary's actual entry stretches further than that single gloss, and linguists still dispute whether the word traces to a taro plant or an older Proto-Polynesian word for "nest."
Why mahalo and aloha aren't variants of each other
Because mahalo and aloha are the two Hawaiian words most non-Hawaiian speakers already know, and both are three syllables built on the same a-o vowel pattern, it's a reasonable guess that they're related, one word bent two ways. They aren't. The Pukui & Elbert dictionary tags aloha, "love, affection, compassion...greeting, salutation," with its own separate Proto-Polynesian source, ʻalofa, an entirely different ancestor from mahalo's masalo. Aloha's use as a greeting and farewell (as well as a general expression of love and compassion) and mahalo's use as a thank-you sit on unconnected etymological branches; they only sound like siblings.
The dictionary entry for aloha also notes that two of its most familiar compounds, aloha ahiahi ("good evening") and aloha kakahiaka ("good morning"), were introduced after contact with Europeans, built later on the older root rather than inherited from it. Pukui and Elbert don't flag either of mahalo's two senses the same way, though that's a separate question from how old the "thanks" sense itself is: some sources point to Lorrin Andrews' 1865 Hawaiian dictionary as evidence that mahalo's use as a straightforward "thank you" hardened only after Western contact, a claim about the word's history that the Pukui & Elbert entry alone doesn't settle either way.
Where mahalo actually shows up
Mahalo nui loa ("thank you very much") and the near-synonym mahalo ā nui are the standard ways to intensify a plain mahalo, the Hawaiian equivalent of adding "so much" or "very" to an English thanks. There is no separate formal register the way some languages mark politeness with an entirely different word; degree does that work instead, a single mahalo for an everyday thanks, mahalo nui loa when the moment calls for more.
Outside conversation, mahalo is one of the most visible Hawaiian words on public signage across the islands: on trash-can lids and doors, at park exits, on restaurant receipts, at airport gates. That visibility has produced a well-known local joke about visitors who see "MAHALO" stenciled on a Waikiki fast-food trash bin and conclude it must be the Hawaiian word for garbage or trash. It isn't; the sign is thanking people for throwing their trash away, not labeling the bin. The actual Hawaiian and Hawaiʻi Pidgin word for trash or rubbish is ʻōpala, an unrelated word.