Astronauts Thomas K. Mattingly and Henry W. Hartsfield put the frosting on the nation's birthday cake today, flying the space shuttle Columbia to a perfect landing on a three-mile-long concrete runway in the Mojave Desert.

Returning to Earth on the Fourth of July after seven days in space, Mattingly and Hartsfield brought Columbia home through 12-knot headwinds to a flag-waving throng of more than half a million and a delighted President Reagan, who called the astronauts "pathfinders" in the frontier tradition of America.

"They reaffirmed to all of us that as long as there are frontiers to be explored and conquered, Americans will lead the way," Reagan said in a welcoming speech in front of an earlier shuttle, the Enterprise, decked out in red, white and blue bunting for the occasion. "They and other astronauts have shown the world that Americans still have the know-how and Americans still have the true grit that tamed a savage wilderness."

But while Reagan pledged a "more permanent presence in space" for the nation, he disappointed National Aeronautics and Space Administration officials who had hoped for a presidential commitment to a permanent space station, or at least a fifth spaceliner (four are authorized).

His 10-minute address made no mention of a fifth shuttle or a space base, which would cost between $4 billion and $6 billion. NASA officials say that if the money was available, a station could be in orbit as early as 1988 with anywhere from 12 to 24 astronauts on board.

Disappointed as they might have been with Reagan's speech, space agency officials could only have been pleased with the performance of astronauts Mattingly and Hartsfield. Not only did the astronauts bring Columbia down onto a concrete runway instead of the desert floor for the first time, they landed precisely where they were expected.

"Welcome back to Earth," astronaut Brewster Shaw called to the crew from the Mission Control Center at the Johnson Space Center in Houston. "That looks like a beautiful vehicle."

Touching down 3,000 feet beyond the runway's threshhold, Mattingly and Hartsfield used another 8,000 feet of concrete to roll to a stop, 4,000 feet from the end of the runway. Their wheels were on the white markers smack in the middle of the 300-foot-wide strip.

NASA officials had hoped to attempt a crosswind landing in this, the last of the shuttle's four test flights. But the wind refused to cooperate. Had the wind been a little stiffer, the astronauts would have attempted a crosswind landing on the desert floor.

"We now feel confident landing on the hard-surface runway at the Kennedy Space Center," Air Force Lt. Gen. James A. Abrahamson, associate administrator for space transportation, said. "That doesn't mean we're going to land at Kennedy on the next flight because we'd still like a crosswind landing, but it does give us confidence."

Abrahamson made it clear that the space shuttle passed its test flight course with flying colors and is ready for duty. The first operational flight is scheduled for Nov. 11, when the Challenger will carry a communications satellite for Canada and another for the Satellite Business Systems Corp. Each customer will pay NASA $21 million if the satellites are left safely in orbit.

Today's celebration belonged to the astronauts, who were praised time after time by Abrahamson, NASA administrator James M. Beggs and Reagan for the way they handled the mission. "You have brought us a Fourth of July present to remember," a beaming Reagan told them. "Hank and T. K., we need not fear for the future of our nation as long as we've got men like you to serve it."

The day dawned in the California desert with the vivid reds of a perfect sunrise, almost as if it were a good omen of things to come. Even before the sun had risen, about 525,000 people in cars, vans, buses and trailers had made they way to half a dozen viewing sites to celebrate the Columbia's holiday return.

Spectators everywhere were waving flags and wearing combinations of red, white and blue.

Out over the South Pacific, Mattingly and Hartsfield began their descent in the dark, whistling past Guam at almost 26 times the speed of sound. Banking left, then rolling right, the astronauts had slowed to less than 12 times the speed of sound as they passed east of Hawaii.

By the time they crossed the California coast between Santa Barbara and Ventura, Columbia had slowed to four times the speed of sound and had fallen to an altitude of 112,000 feet.

"Take her on down," Shaw, at Mission Control in Houston, said. "You're go for Edwards."

Minutes later, the double sonic boom from the shuttle and a chase plane could be heard over the desert as Mattingly and Hartsfield flew almost directly over the landing site at an altitude of 50,000 feet.

Suddenly, the delta-winged spaceliner was visible to the naked eye as it swooped toward Edward's concrete runway. Mattingly, taking over the controls at 2,500 feet, guided Columbia to a flawless landing almost directly in front of Reagan.

After being greeted by the Reagans, Mattingly and Hartsfield gave the president and first lady a tour of the nose of the spacecraft. At the urging of the astronauts, Mrs. Reagan touched the shuttle's nose gear, which was still warm from the scorching heat of reentry. Moments later, the president did likewise.

"I just want to repeat how proud we are of you," Reagan said. "God bless you all and a happy Fourth of July."