As known, nitrogen could form 3 bonds based on octet rule, because it has 5 valence electrons. That means it needs 3 bonds.
On the other hand, why sometimes nitrogen forms 4 bonds?
As known, nitrogen could form 3 bonds based on octet rule, because it has 5 valence electrons. That means it needs 3 bonds.
On the other hand, why sometimes nitrogen forms 4 bonds?
I'd like to try answer the question from the title regarding the maximum number of atoms nitrogen is capable of bonding with, and also slightly expand my comment.
Metal nitrido complexes are commonly known to have up to 6 metal centers bound with a single bridging $\ce{N3−}$ ion, located in an octahedral cavity. An interstitial nitrogen can contribute 5 electrons, and the rest is provided by the group 9 and 10 metals which are electron-rich (typically, $\ce{Rh}$, $\ce{Ir}$).
There are few more exceptions where formal C.N. for nitrogen is 7: complexes of lithium amides based on $\ce{\{Li14N10\}^{6-}}$ cluster framework [1,2] and an inclusion nitrido-cluster $\ce{\{Co2RhN2\}^{3-}}$ [3]. Unfortunately in both crystal structures [1,2] with 6- and 7-fold coordinated nitrogens of $\ce{N-Ar}$ groups those are heavily disordered. Structure [3] is more suitable for the representation.
tris(Tetramethylammonium)($\mu_7$-nitrido)-($\mu_6$-nitrido)-decakis($\mu_2$-carbonyl)-undecacarbonyl-deca-cobalt-rhodium(I) $\ce{[Co10RhN2(CO)21]^3-}$ [3] contains two non-equivalent 6- and 7-fold coordinated nitrogen atoms ($\mathrm{N2}$ and $\mathrm{N1}$, respectively), sharing a triangular face:
$\color{#909090}{\Large\bullet}~\ce{C}$; $\color{#3050F8}{\Large\bullet}~\ce{N}$; $\color{#FF0D0D}{\Large\bullet}~\ce{O}$; $\color{#F090A0}{\Large\bullet}~\ce{Co}$; $\color{#0A7D8C}{\Large\bullet}~\ce{Rh}$;
Cluster core wireframe model without carbonyl ligands:
Atom $\mathrm{N1}$ with C.N. 7 is coordinated with 6 cobalts and 1 rhodium, forming a capped trigonal prism. Interestingly enough, $\mathrm{Co1}$ is a capping atom, not rhodium:
N1 SYMM Co5 Co4 Co6 Co3 Co2 Rh1 Co1
Co5 1.90 I - - - - - - -
Co4 1.91 I 135.0 - - - - - -
Co6 1.92 I 79.5 80.2 - - - - -
Co3 1.98 I 129.7 85.1 80.2 - - - -
Co2 2.00 I 82.3 140.2 128.4 75.4 - - -
Rh1 2.18 I 80.7 81.1 128.3 144.9 95.3 - -
Co1 2.43 I 143.5 70.3 136.5 66.4 70.1 78.6 -
Both interstitial nitrogens play the role of internal ligands, which provide cluster valence electrons (CVE), but don't contribute to steric hindrance between external ligands such as carbonyls, making the cluster more stable [4, ch. 1.18]
Nitrogen has three electrons in its 2p orbital. Therefore, it can form three bonds by sharing its three electrons. It cannot accept any more electrons but here's how it forms the fourth bond.
Nitrogen has one lone pair of electrons in its 2s orbital. It can donate this electron pair to form a coordinate bond. This coordinate bond that nitrogen forms by donating its electron pair to the vacant orbital of other atom is how it can form 4 bonds.