Gas Gauge

My gas gauge keeps telling me i'm out of gas when I still have about 2-3 gallons left. It ran out today and when I filled it up it still apparently had 4 gallons in it. Is there a sensor I need to replace? (Sorry if searching would solve the problem, but I'm at school right now
)
