A financial safety net for older Americans, Social Security was established in 1935 by the Social Security Act. Before that, support for the elderly wasn't a federal concern - it mostly fell to states, towns and, of course, families.
The program is based on contributions that workers make into the system. While you're employed, you pay into Social Security; you receive benefits later on, when it's your turn to retire. Contributions take the form of the Federal Insurance Contributions Act (FICA) taxes that are withheld from most paychecks.
Medicare benefits are commonly considered part of Social Security benefits, although technically Medicare is a separate program. Medicare contributions are withheld from your paycheck in much the same way as your Social Security contributions; FICA taxes support Social Security and Medicare.