Yes, your options differ, depending on which airport you are transiting at.
If both your transits are through NRT, I'd suggest checking into one of the business hotels US$100 or less for a single) in the town of Narita and perhaps seeing Shinshoji Temple in the morning, maybe doing a bit of shopping. If your layovers were during daylight hours, I'd suggest going to Tokyo, the city mostly does shut down after midnight.
I gave up hostels a few decades ago, so I don't know about current options for backpackers' lodgings, but I'm sure Google will help you there.
If both your transits are through HND, then you are technically in central Tokyo and have more options. You definitely have time to check into a hotel and get in a bit of wandering around before midnight and in the early hours of the next morning.