What the setting tells you
Hummingbirds flying back and forth usually have a clear reason, and the place matters most. A bird that keeps returning to a feeder or a patch of flowers is probably feeding or guarding them. One that keeps going back to a window is probably reacting to the glass. A bird that keeps circling a room or garage is most likely trying to get out.
Whether other hummingbirds are around helps too. A male that chases another bird away from food is guarding it. A male that flies side to side in front of a perched bird, without chasing it off, may be displaying to a female.
Feeding or guarding at a feeder
Feeders draw repeated visits during hummingbird feeder season. A bird that keeps returning may simply be feeding on a regular route, which is ordinary. If one bird chases others off and then returns to a perch near the feeder, it is probably guarding. Hummingbird guarding feeder behavior is usually a male defending the food, and it can look like a series of short flights out and back.
If one bird seems to control a feeder, adding a second feeder some distance away can help spread the visitors out.
Courtship
Some species, such as Allen’s and Anna’s hummingbirds, are described performing a display in which the male flies side to side in front of a perched female. If the flying looks like that, and nothing is being fought over, courtship is the likelier cause. Displays like this are part of hummingbird mating behavior, and they happen during the breeding season.
Hunting insects
Short, repeated flights out from a perch and back can mean the bird is catching insects. Hummingbirds take small insects and spiders as well as nectar, and they often grab them in midair. This is part of how hummingbirds eat, not a sign that anything is wrong.
Reflections at a window
A hummingbird that keeps returning to one window may be reacting to its reflection. Birds sometimes treat the reflection as a rival, and that response is more common in spring, when males are setting up territory.
Fixes work best on the outside of the glass. Decals or netting break up the reflection, and treatments on the inside generally do not do the job.
Trapped indoors
If a hummingbird is flying back and forth inside a house or garage, it is likely trying to find the way out. Close the door to the other rooms, turn off the lights in the room if you can, and open an outside door or window. Keep pets out and wait quietly. A bird that is not hurt often leaves once it sees daylight.
When it needs help instead
Flying back and forth in the air is normal behavior. A bird that is sitting on the ground, cannot fly, or seems weak needs different steps. If you have found a hummingbird on the ground, follow different guidance from the steps above, and a wildlife rehabilitator can advise you on the next move.
The place, the timing and whether other birds are involved usually point to one reason. Watching a few visits tells you more than a single flight does.