Whales’ “noses”, or blowholes, are on the top of their heads, so that they can just barely break the surface to breathe without rising too far out of the water. When inhaling, they flex a muscle which opens the blowhole and take in a big gulp of air. Then, they relax the muscle to close the blowhole, leaving them free to dive down beneath the surface of the water once more without drowning themselves.
It’s exhaling that’s the interesting part. When the whale resurfaces, they have to release the used up air back into the atmosphere just like all other mammals do. This results in a spout, but it isn’t water (at least not at first). The air inside the whale is typically quite warm from the whale’s body heat. When it’s exhaled, it meets the much cooler temperature of the air outside and immediately condenses, making it look like a spout of water. (This is also often mixed with mucus —it is a nose, after all!)