Short answer: most spiders cannot swim in any real sense. Some can run across the surface of the water, a few hunt underwater, and one well-known species lives its whole life underwater. What makes the difference is body hairs, leg structure, and how a spider traps air.
Why most spiders sink
Most spiders are not built for swimming. Their legs are designed to push against solid ground and plants, not to paddle through water, and their bodies are not shaped for moving through liquid. A spider that falls into water usually struggles, may float briefly, and can drown if it stays submerged too long.
Walking and running on water
Some spiders are light enough to rely on surface tension, the force that lets water hold up small objects. Fishing spiders (genus Dolomedes) can run across the surface of a pond or stream, and the water-repellent hairs on their legs help them stay on top. They hunt small fish, tadpoles, and aquatic insects from the water’s edge or from the surface.
Trapping air to breathe underwater
Many spiders have water-repellent hairs covering their bodies. When a spider is submerged, a thin layer of air can cling to these hairs. That air layer can give the spider a limited supply of oxygen while it is underwater, because the spider’s breathing organs can still take oxygen from it. The layer does not last forever. It can be lost over time, and the spider eventually needs to get back to the surface or out of the water.
The breathing organs involved are described in spider anatomy.
The diving bell spider
The diving bell spider (Argyroneta aquatica) is the best-known spider that lives underwater. It is found in parts of Europe and Asia, and it spins a silk web shaped like a bell, anchored to plants underwater. It carries air down from the surface on its body hairs and fills the bell with it. The spider then uses the bell to eat, rest, mate, and lay eggs. It is a useful example of how a spider can live fully underwater.
Spiders that survive floods
Some ground-dwelling spiders can survive temporary flooding by staying in sealed, silk-lined burrows. Research on this is limited, so it is safer to describe it as a possibility for some species rather than a common ability across spiders.
Can a spider drown?
Yes. Most spiders cannot stay submerged indefinitely. A spider trapped in water for a long time, or one that cannot get out or hold a stable air layer, can drown. If you find a spider floating in a pool or a bucket, you can lift it out gently with a cup or a leaf, then let it dry in a sheltered spot.
For how spiders breathe in general, including book lungs and tracheae, see spider anatomy. For a related question about how spiders respond to harm, see do spiders feel pain.