I saw a water heater stand at Home Depot but it's about 15" high. That's a bit too high for my basement. Can I just make one with 2x4 and plywood that's only 4" tall, basically just enough to be able to drain water off the drain tray? Or does the code require it be higher?
Regardless of code, I like to get them off the floor just in case the basement floods. My preferred (and easily available anywhere) solution is a few solid concrete blocks; one under each foot. You can stack them if you want, too. This is an easy way to increase the height in 4" increments.
I don't suggest using lumber. If your floor is the least bit hygroscopic, it will rot from the underneath even if the tank never leaks.
16" x 8" x 4" Solid Concrete Block:
Check the manufacturer's installation instructions for the heater. As far as I'm aware, a gas appliance only has to be raised off the floor if there's a possibility of flammable vapors being near it (e.g. in a garage).
IRC P2801.6 Water heaters installed in garages. Water heaters having an ignition source shall be elevated such that the source of ignition is not less than 18 inches (457 mm) above the garage floor.
Plumbing code requires ¼" per foot slope in drain pipes that are 2 ½" or less in diameter. So as long as the drain maintains that slope, the heater can be as low as you want.
Water heaters only need to be raised (per code) if they are using an ignitable fuel source (gas, propane, etc). And even then, the code is that the ignition mechanism is what needs to be raised.
If your water heater is electric or a heat pump, no need to raise it per code.
But if you WANT to raise it then you certainly can, though building something is likely overkill. They make water heater pads that are just blocks of insulation foam. Here's one from Home Depot for $11:
Cheap, easy to install, and add some additional insulation.
re: "Can I just make one with 2x4 and plywood that's only 4" tall, basically just enough to be able to drain water off the drain tray? Or does the code require it be higher?"
I imagine you 'can' do that, but I wouldn't recommend that you do that.
I recommend you do the following:
1. Contact the Building & Code Enforcement office in your location to determine what (if any) codes regulate such a change to your water heater.
2. If they give you the go ahead & inform you of any regulations that you must follow, then ensure your water connection hoses are flexible enough to withstand the lift that you intend to make (you may need to replace rigid or semi-rigid connection piping with properly pressure & heat rated braided hoses. Also, double check your overflow piping to ensure that it will be adequate after the lift (this may require you to install a pipe extension or replace the down pipe so it isn't too high above the drain pan (which could cause scalding if you have an over-pressure situation)
3. If everything above looks good, then use good brick (not wood) as a base for your water heater.
As @Tester101 points out, IRC P2801.6 sets the minimum when you're installing an ignition-type heater in a garage.
In other situations, here are two things I consider when installing stands for "classic" tank-style water heaters:
We have hard water in our area, so it is nice to drain the crud out of the tank once a year. Having the water heater off the floor high enough to comfortably connect a hose to the drain valve is nice.
Replacing the anode periodically extends the life of the tank. Anode replacement is easier if you have at least a tank height of free space above the installed heater. That much clearance above will save you from searching out linked anodes.
I came across this and, despite it's age, merited some amendment: Gas water heaters now have to be installed with the burner 18" above ground in a garage unless the heater is specifically classified as a "Flammable Vapor Ignition Resistant" (FVIR). (Ref: International Residential Code, section G2408.2 - Elevation, Exception)
Most if not all such heaters manufactured since roughly 2003 or so are inherently FVIR. That's not to say elevating them from ground installation might not still be advantageous for water reasons, but the gas ignition concern has been significantly mitigated.