Developing a brand-new medicine costs a great deal in research, testing and marketing, and the original company recovers those costs while it holds the patent. Generic manufacturers come in after the patent expires and do not carry those large upfront costs, so they can sell for less.
Competition adds to the savings. Once multiple companies make the same generic, prices fall further. None of this reflects lower quality, because generics must meet the same regulatory standards for the active ingredient.
Choosing a generic is usually a simple way to reduce costs without reducing effectiveness. If cost is a barrier to taking any medicine, tell your pharmacist or doctor, who can often suggest a cheaper equivalent or other options.