Nadal, a two-time champion at the Indian Wells Tennis Garden, had missed seven months because of a left knee injury and hadn't played on a hard court since March 29, 2012.
The Spanish star returned to the ATP Tour a month ago and played three tournaments on clay, winning two of those and saying his knee felt better each week.
But he said in a pre-match news conference that he had no idea how the knee would hold up under the stress of a harder surface and he had no expectations in terms of results.
Nadal took a 4-1 lead in the opening set with a performance that he rated as "nothing special but OK," then lost three games in a row as Harrison pulled even. Nadal reasserted himself in the tiebreaker, racing out to a 5-1 lead, and he took control of the second set by winning five games in a row after Harrison had held serve to open the set.
"He started passing a lot better," Harrison said. "I was just kind of throwing him off rhythm a little bit with mixing the serve and volley. I think once I let that tiebreaker slip away a little bit and he got ahead he started loosening up and swinging out a little more."
Nadal was pleased to be moving on.
"I am satisfied to be in the next round. That's the most important thing," said Nadal, seeded fifth. "Two weeks ago I didn't really know if I would be here playing. I am happy to be here. I am happy to be in the third round. Good victory for me today against a good opponent.
"I am fine. My physical performance needs to improve. My movements need to improve. Matches like this help me, for sure, no? Today, any victory is important for me. If you win, you have more chances. If you have more chances, you will compete more and you will practice more and you will be ready to put yourself in 100 percent condition in a short period of time. If you are losing very early it's tough because you can practice a lot, but at the end it's not enough, the practice. The important thing is to compete."
Federer, who won his fourth title here last year, lost just four points on serve, all in the first set.
Two of those were by double faults, and he never faced a break point and won 96 percent of his first serves.
"It felt good from the start and I was able to maintain that level of play," Federer said. "I never thought he got into the match at all. That gives you obviously even more confidence."
"I did what I could," Hewitt said. "I think I handled his serve pretty well and I made him hit a lot of balls.
"I felt like I had more chances throughout the match. The first set could have gone either way and then I dug deep early in the second set to get up a break. That was a big momentum change."
The second of the two service breaks by Hewitt, in game seven of the third set, gave the 2002-2003 champion a 4-3 lead. He added to it by holding serve for 5-3. Then, after Isner held for 5-4, Hewitt served out the match.
It didn't come easily, however. He got to 40-15 with a forehand pass, then lost three match points and fought off a break point before securing the win with a forehand down the line.
In other matches, Benoit Paire of France beat No. 20 Philipp Kohlschreiber, Jarkko Nieminen of Finland topped No. 28 Fernando Verdasco and Leonardo Mayer of Argentina eliminated No. 30 Mikhail Youzhny of Russia.