If an NPC has joined the party and acts like a regular party member (so-called "recruitable NPCs"), I calculate XP normally and level them up accordingly.
For non-recruitable major NPCs (key allies, villains, plot characters) I level them up as much as I feel is appropriate/necessary, though...