Shipboard
As you surmise, when aboard ship, the commbadge offloads all the routing to the ship's main computer:
During voice operations, the normal procedure involves a crew member stating his or her name, plus the party or ship area being called, in a form that can be understood by the computer for proper routing. Examples: "Dr. Selar, this is the captain," or "Ensign Nelson to Engineering." The artificial intelligence (Al) routines in the main computer listen for intraship calls, perform analyses on the message opening content, attempt to locate the message recipient, and then activate the audio speakers at the recipient's location.
Planetside
The range of the communicator is very limited
due to the small size of the STA [subspace transciever assembly] clear voice signals will only propagate 500 kilometers. This is a tiny fraction of the 40,000 km required to contact an orbiting spacecraft, so it is the spacecraft that must become the active partner in order to receive the communicator's lower-power signals, and transmit correspondingly high power signals to the communicator's receiver.
Communications between the starship and a destination typically 38,000 km to 60,000 km away from the antennae are handled by the [hull-mounted RF and subspace] radio systems. Situations encountered cover a broad range, but most notably include discussions with planetside governments, communication and control of Away Team operations ...
Given this, it seems that likely the comm badge still routes its traffic via the ship's main computer systems (when available) through its STA (which makes sense, as the ship keeps as constant a lock on the comm badges as possible for transport, and would allow for monitoring and logging of away team activity while planetside). When it is not possible to communicate with the ship, the control program within the badge itself is presumably capable of cutting out the middle man and establishing communication directly either through the RF transponder (thus acting effectively like a cell-phone) or the STA, and the control program is responsible for identifying whether a signal it is receiving is intended for this unit or not.
(As a side note that the technical manual claims "the communicator is a line-of-sight device away missions", though this seems to have been contradicted plenty of times on screen, so I am disregarding that paragraph.)
All images and quotations taken from the TNG Technical Manual.