Some of Silicon Valley’s biggest companies are on a real estate buying binge, paying premium prices to make sure they have enough space for future expansion.

Facebook Inc. is the latest to dive in, agreeing last month to spend $395 million for Menlo Science and Technology Park, a jumble of 21 low-slung warehouses and office buildings 30 miles southeast of San Francisco. It’s now home to an orthopedic surgical tools company, a supermarket distribution center and a storage facility for an office-furniture company.

...