How to know if hurt or sprained your foot before where it was swollen and partly black and blue?

See a Podiatrist. A podiatrist can take x-rays and may order an MRI to see if there were torn ligaments or tendons. If you are having pain it is important to do this sooner rather than later to avoid continued injury.