Rows are users, columns are items. Cell colour is the rating (1–5); hatched cells are unknown. The yellow outline marks the target cell to predict, blue outlines mark the chosen neighbour rows.
$$\hat r_{u,i}=\bar r_u+\frac{\sum_{v\in N}\text{sim}(u,v)\,(r_{v,i}-\bar r_v)}{\sum_{v\in N}|\text{sim}(u,v)|}$$
Predicted rating $\hat r_{u,i}$ of user $u$ for item $i$. $N$ is the set of the $k$ most similar users who have rated item $i$, and $\bar r_u$ is the mean rating of user $u$.
$$\text{cos}(u,v)=\frac{\sum_{j} r_{u,j}\,r_{v,j}}{\sqrt{\sum_j r_{u,j}^2}\,\sqrt{\sum_j r_{v,j}^2}}$$
Cosine similarity. The index $j$ runs over the items both $u$ and $v$ have rated. The smaller the angle between their rating vectors, the closer it is to 1.
$$\text{pear}(u,v)=\frac{\sum_{j}(r_{u,j}-\bar r_u)(r_{v,j}-\bar r_v)}{\sqrt{\sum_j(r_{u,j}-\bar r_u)^2}\,\sqrt{\sum_j(r_{v,j}-\bar r_v)^2}}$$
Pearson correlation. Because each user's mean rating is subtracted before correlating, it corrects for generous-versus-harsh rating habits.